Running a stateful Pod

Let's see another use case. We used Deployments/ReplicaSets to replicate the Pods. It scales well and is easy to maintain and Kubernetes assigns a DNS to the Pod using the Pod's IP address, such as <Pod IP address>.<namespace>.pod.cluster.local.

The following example demonstrates how the Pod DNS will be assigned:

$ kubectl run apache2 --image=httpd --replicas=3deployment "apache2" created//one of Pod has an IP address as$ kubectl get pods -o wideNAME                       READY     STATUS    RESTARTS   AGE       IP          NODEapache2-55c684c66b-7m5zq   1/1       Running   0          5s   gke-chap7-default-pool-64212da9-z96qapache2-55c684c66b-cjkcz   1/1       Running   0          1m   gke-chap7-default-pool-64212da9-8gzmapache2-55c684c66b-v78tq 1/1 Running 0 1m ...

Get Kubernetes Cookbook, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.