Skip to content

Expose a Service

When to Use This Guide

Use this guide when you need to make an application accessible through a Kubernetes Service.

Services provide a stable network endpoint that allows other pods or external clients to access your application.


Quick Commands

kubectl expose deployment web-app --port=80 --target-port=8080
kubectl get services

Service Types

Type Description Use Case
ClusterIP Internal cluster access Communication between pods
NodePort External access via node IP Simple external exposure
LoadBalancer External load balancer Cloud environments

Step 1 — Verify the Deployment

Check that your application pods are running.

kubectl get pods

Example:

web-app-6f9c8c7b7d-xk92
web-app-6f9c8c7b7d-lm12a


Step 2 — Create the Service

Expose the deployment.

kubectl expose deployment web-app \
  --type=ClusterIP \
  --port=80 \
  --target-port=8080

This creates a service that forwards traffic to the application pods.


Step 3 — Verify the Service

Check service status.

kubectl get services

Example:

NAME      TYPE        CLUSTER-IP     PORT(S)
web-app   ClusterIP   10.96.120.45   80/TCP


Step 4 — Test Internal Access

Test the service from another pod.

kubectl run curl --image=curlimages/curl -it --rm -- sh

Then inside the pod:

curl http://web-app


Common Issues

Service Cannot Reach Pods Check service selectors.

kubectl describe service web-app

Verify labels match pod labels.


Pods Not Ready

Services only route traffic to ready pods.

Check readiness:

kubectl get pods


Quick Workflow

kubectl get pods
kubectl expose deployment web-app --port=80 --target-port=8080
kubectl get services


Networking

  • Expose Service with Ingress
  • Port Forward Pod

Troubleshooting

  • Debug a Crashing Pod