Project projet11-kubernetes-services · useful theory before (or during) the practice.
A Pod is ephemeral: it can be deleted, recreated, moved to another node — and its IP address changes. Impossible, then, to hard-code a Pod IP.
The Service solves this problem: it provides a stable address (IP + DNS name) and automatically distributes traffic to all Pods that match its label selector.
The Service → Pods link is not a frozen IP: it is a label selector. Kubernetes maintains the list of matching Pods by itself (the Endpoints).
http://demo-clusterip).http://<node-ip>:<nodePort> (here http://localhost:30082).EXTERNAL-IP becomes localhost (http://localhost:8090).| Type | Scope | Access | Typical use case |
|---|---|---|---|
| ClusterIP | Internal | Internal DNS name | Database, internal API, Pod↔Pod communication |
| NodePort | External | localhost:<30000-32767> | Demo / local dev |
| LoadBalancer | External | Public IP (localhost locally) | Public service in cloud production |
There is also ExternalName (DNS alias to an external service) and Ingress (HTTP/HTTPS routing by domain name, seen later) — outside this project.
Kubernetes runs CoreDNS in the cluster. Each Service receives a DNS name:
<service-name> # from the same namespace
<service-name>.<namespace> # from another namespace
<service-name>.<namespace>.svc.cluster.local # full name (FQDN)Thus, from any Pod in the same namespace:
curl http://demo-clusterip # resolved by CoreDNS -> Service IP -> a PodIP:port, updated automatically by Kubernetes.kubectl get endpoints demo-clusterip # shows the Pod IPs behind the ServiceCourse created by Dr. Haythem REHOUMA — Development and Deployment of Data Solutions