appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Services and networking

Lesson 3 of 510 minIntermediate

Pods come and go and their IPs change. A Service gives a stable name and address in front of them.

Every pod gets its own IP address, but pods are replaced all the time and their addresses change. A Service is a stable virtual address and DNS name that sends traffic to the healthy pods that match a label selector.

service.yaml
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
    - port: 80
      targetPort: 80

Inside the cluster, other pods reach it as web (or web.default.svc.cluster.local). Cluster DNS resolves that name to the Service address.

Service types

TypeWho can reach itTypical use
ClusterIP (default)Only inside the clusterInternal services and databases
NodePortOutside, on a port of every nodeSimple tests, small setups
LoadBalancerOutside, through a cloud load balancerPublic apps on a cloud provider

Ingress

An Ingress routes HTTP and HTTPS traffic by host name and path (for example /api to one Service and / to another). It needs an ingress controller installed in the cluster to work.

NoteFor quick access to a Service from your laptop, use kubectl port-forward service/web 8080:80.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. Why do you put a Service in front of pods?
2. Which Service type is only reachable from inside the cluster?
3. What does an Ingress add?

Key terms