codegurukool.com · Free coding tutorials & online compiler

Home › Kubernetes Tutorial › Services

Services

A stable address for changing Pods.

Pods come and go and their IP addresses change. A Service gives a group of Pods one stable name and IP, and spreads traffic across them. It finds Pods with a label selector. Inside the cluster other Pods can reach it by name, for example http://web.

Example code

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

Run this code in the online editor

← Scaling and rolling updatesService types: ClusterIP, NodePort, LoadBalancer →