OpsCanary
Back to daily brief
kubernetesnetworkingPractitioner

Mastering Kubernetes Services: The Key to Network Application Exposure

5 min read Kubernetes DocsApr 21, 2026
PractitionerHands-on experience recommended

Kubernetes Services exist to simplify the exposure of network applications running in your cluster. They provide a stable endpoint for accessing Pods, which can be dynamic and ephemeral. Without Services, you’d need to manage direct Pod IPs, which can change frequently, leading to a fragile setup. Services abstract this complexity, allowing you to focus on your application rather than the underlying infrastructure.

The Service API defines a logical set of endpoints, typically Pods, and includes policies for accessing them. Each Service has a selector that matches Pods based on labels, ensuring that traffic is routed correctly. Key configuration parameters include port, which specifies the Service’s listening port, and targetPort, which directs traffic to the appropriate port on the Pod. The default protocol is TCP, making it suitable for most applications. Here’s a basic example:

YAML
1apiVersion: v1
2kind: Service
3metadata:
4  name: my-service
5spec:
6  selector:
7    app.kubernetes.io/name: MyApp
8  ports:
9    - protocol: TCP
10      port: 80
11      targetPort: 9376

In production, you need to be aware of certain gotchas. Ensure that endpoint IPs are not loopback or link-local addresses, as these will cause issues. Also, avoid using cluster IPs of other Services as endpoints, since kube-proxy doesn’t support virtual IPs as destinations. These nuances can trip you up if not handled correctly. Remember that Kubernetes v1.34 introduced some changes, so always check your version compatibility when implementing Services.

Key takeaways

  • Understand the role of Services in exposing Pods over the network.
  • Configure `targetPort` correctly to ensure traffic reaches the right container port.
  • Avoid using loopback or link-local IPs for endpoints to prevent connectivity issues.
  • Use the selector feature to dynamically manage Pods as they scale up or down.

Why it matters

In production, Services are critical for maintaining stable access to your applications, especially as Pods are created and destroyed. They help ensure that your services remain available and resilient to changes in the underlying infrastructure.

Code examples

YAML
apiVersion:v1kind:Servicemetadata:name:my-servicespec:selector:app.kubernetes.io/name:MyAppports:-protocol:TCPport:80targetPort:9376
YAML
apiVersion:v1kind:Servicemetadata:name:nginx-servicespec:selector:app.kubernetes.io/name:proxyports:-name:name-of-service-portprotocol:TCPport:80targetPort:http-web-svc---apiVersion:v1kind:Podmetadata:name:nginxlabels:app.kubernetes.io/name:proxyspec:containers:-name:nginximage:nginx:stableports:-containerPort:80name:http-web-svc
YAML
apiVersion:discovery.k8s.io/v1kind:EndpointSlicemetadata:name:my-service-1# by convention, use the name of the Service# as a prefix for the name of the EndpointSlicelabels:# You should set the "kubernetes.io/service-name" label.# Set its value to match the name of the Servicekubernetes.io/service-name:my-serviceaddressType:IPv4ports:-name:http# should match with the name of the service port defined aboveappProtocol:httpprotocol:TCPport:9376endpoints:-addresses:-"10.4.5.6"-addresses:-"10.1.2.3"

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.