liveBook · Manning

Service IP

As explained in Kubernetes in Action, Second Edition

A cluster IP is the virtual network address assigned to a Kubernetes Service for receiving and forwarding traffic to its endpoints.

A service IP, or cluster IP, is the internal address assigned to a Kubernetes Service. It gives workloads inside the cluster one address for reaching a group of pods, even when individual pod IPs change. Kubernetes normally assigns the address when the Service is created. section 11.1.2 section 11.7

Listing 11.1 YAML manifest for the quote Service object
apiVersion: v1    #1
kind: Service    #1
metadata:
  name: quote     #2
spec:
  type: ClusterIP      #3
  selector:          #4
    app: quote       #4
  ports:                 #5
  - name: http           #5
    port: 80             #5
    targetPort: 80       #5
    protocol: TCP        #5

This Service manifest requests type ClusterIP, selects pods labeled app: quote, and makes them available on port 80. It leaves the clusterIP field unset so Kubernetes can assign the address. section 11.1.2

Run kubectl get svc -o wide to see a Service’s CLUSTER-IP, ports, and label selector. The selector determines which pods receive traffic; the Service’s endpoints can change without changing its IP. Endpoints can also be managed manually when no selector is set. section 11.1.2 section 11.7

Call a Service from a pod

A pod can call a Service by IP, such as curl http://10.96.136.190, but an application can use its DNS name instead: curl http://quiz. A lookup of a Service’s A record returns its cluster IP; even a LoadBalancer Service’s internal DNS lookup returns the cluster IP rather than its external address. section 11.1.3 section 11.4.1

The IP is virtual: it works with a port defined by the Service. If curl reaches the Service but ping gets no replies, the failed ping does not establish that the Service is broken. The cluster IP is for access inside the cluster; NodePort and LoadBalancer services also provide access from outside. section 11.1.3 section 11.7

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains assignment, inspection, DNS lookup, and the virtual IP’s port requirement, without detailing packet-forwarding internals.
Examples
Uses a Service YAML manifest, kubectl get svc output, in-pod curl requests, DNS lookups, and a failed ping.
What it assumes
Introduces the cluster IP as an internal Service address while using pods, selectors, and kubectl in the examples.
What you can do after
Operate/configure it by inspecting a Service’s cluster IP and using its IP or DNS name for in-cluster requests.
How it connects
Connects Service IPs to label selectors, endpoints, cluster DNS, and Service types.

Also explained in

Compare how 3 books explain service IP →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.