Services
A service is an abstraction for pods, providing a stable, so called virtual IP (VIP) address. While pods may come and go and with it their IP addresses, a service allows clients to reliably connect to the containers running in the pod using the VIP. The "virtual" in VIP means it is not an actual IP address connected to a network interface, but its purpose is purely to forward traffic to one or more pods. Keeping the mapping between the VIP and the pods up-to-date is the job of kube-proxy, a process that runs on every node, which queries the API server to learn about new services in the cluster.
kubectl apply -f https://raw.githubusercontent.com/openshift-evangelists/kbe/main/specs/services/rc.yaml
kubectl apply -f https://raw.githubusercontent.com/openshift-evangelists/kbe/main/specs/services/svc.yaml
kubectl get pods -l app=sise
kubectl describe pod rcsise-nlfzs
The output should appear similar to the following (which has been truncated for readability):
Name: rcsise-nlfzs
Namespace: default
Priority: 0
Node: minikube/192.168.39.51
Start Time: Thu, 03 Jun 2021 16:52:41 -0400
Labels: app=sise
Annotations: <none>
Status: Running
IP: 172.17.0.3
IPs:
IP: 172.17.0.3
Controlled By: ReplicationController/rcsise
Containers:
sise:
Container ID: docker://907686f441b6f30d8723c1a66ce9348955cded4934573d9a6703173f38a2d705
Image: quay.io/openshiftlabs/simpleservice:0.5.0
172.17.0.3
:
kubectl exec rcsise-nlfzs -t -- curl -s 172.17.0.3:9876/info
simpleservice
, is used to abstract the access to the pod away from a specific IP:
kubectl get service
app=sise
will receive traffic.simpleservice
service endpoint on port 80. KubeDNS even provides basic name resolution for Kubernetes services (within the same Kubernetes namespace). This allows us to connect to pods using the associated service name - no need to including IP addresses or port numbers.
kubectl exec rcsise-6nq3k -t -- curl -s simpleservice/info
Let’s now add a second pod by scaling up the RC supervising it:
kubectl scale --replicas=2 rc/rcsise
Wait for both pods to report they are in the "Running" state:
kubectl get pods -l app=sise
kubectl delete svc simpleservice
kubectl delete rc rcsise