Let's explore deploying a multi-tier application in Kubernetes. Our setup includes:
sudo kubectl create secret docker-registry my-registry-secret \
--docker-username=username \
--docker-password=password \
--docker-email=my@mail.com
kubectl apply -f deploy-redis.yaml
kubectl apply -f service-redis.yaml
kubectl apply -f deploy-greetapp.yaml
kubectl apply -f service-redis.yaml
kubectl get deployments
kubectl get services
kubectl get pods
Shutdown one node and observe pod rescheduling. Then shutdown another node to see the impact. kube-scheduler automatically creates pods on other available nodes.
kubectl get pods
would never have pods in
"Running" state. (verify using
kubectl get pods
)
If all pods are running then simulate memory pressure using deployment scale.
kubectl scale deployment greetapp --replicas=<INT>
kubectl describe node <node-name>|grep -i
pressure
MemoryPressure False KubeletHasSufficientMemory kubelet has sufficient memory available MemoryPressure Unknown NodeStatusUnknown Kubelet stopped posting node status.
kubectl get pods
command will show multiple entries
with evicted pod.
sudo journalctl -u kubelet -f
will show eviction
logs
kubectl get pods
would never have pods in "Running" state. (verify using kubectl get pods
)
If all pods are running then simulate disk pressure by deleting and creating deployments multiple times of multiple version of same app.
Multiple pull different version, fills the disk space.
kubectl describe node <node-name>|grep -i pressure
DiskPressure False KubeletHasNoDiskPressure kubelet has no disk pressure DiskPressure Unknown NodeStatusUnknown Kubelet stopped posting node status.
kubectl get pods
command will show multiple entries with evicted pod.sudo journalctl -u kubelet -f
will show eviction logssudo crictl rmi --prune
sudo crictl rm $(sudo crictl ps -a -q --state=exited)
Before actual deployment, imagine if an app is already deployed. This is where K8s starts getting complicated and leaves systems like Minikube way behind.
Now ask yourself, how would you access the app in kubernetes?
curl <which-ip?>:30008/api/greet -X POST -H "Content-Type: application/json" -d '{"name":"value2"}'
Careful, let's dissect this.
This is the overall CIDR range for the entire cluster's pod network.
--cluster-cidr=10.85.0.0/16
parameter in kubeadm is used to control this.
Learn more: How a Kubernetes Pod Gets an IP Address
--service-cluster-ip-range=10.96.0.0/12
parameter in kubeadm is used to control this.--apiserver-advertise-address
flag, kubeadm will use the IP address of the default network interface (usually the primary network interface) as the advertised IP address.