Reach it as web (same namespace) or web.<namespace>.svc.cluster.local
Apps talk to services by name — never hardcode pod IPs
Inspecting services
kubectl get services
kubectl describe service web — see its endpoints (the pod IPs)
kubectl get endpoints web — the live backend list
Example clusterip
wget https://it3300.cs.utahtech.edu/files/k8s-services-demo.yaml
kubectl apply -f k8s-services-demo.yaml
kubectl -n svc-demo rollout status deployment/whoami
kubectl -n svc-demo get pods,svc -o wide
#temporary client
kubectl -n svc-demo run client --rm -it --image=busybox:1.36 --restart=Never -- sh
#inside client
wget -qO- http://clusterip
#and
for i in 1 2 3 4 5 6 7 8; do
wget -qO- http://clusterip | grep Hostname
done
Example nodeport
kubectl -n svc-demo get svc nodeport
kubectl get nodes -o wide
curl http://NODE_IP:NODE_PORT
Can access from any node ip address of the cluster
Example loadbalancer
kubectl -n svc-demo get svc loadbalancer
#this doesn't work unless we go to cloud
Example ExternalName - DNS Aliasing
Start the temporary client and
nslookup headless
You should see the individual IP addresses of the three Pods rather than one virtual Service IP.
When? Imagine your application runs inside Kubernetes, but PostgreSQL is hosted on AWS RDS.