Kubernetes services
Sample questions
- Create a pod nginx3 with image nginx and exposing port 80
kubectl run nginx3 --image=nginx --port=80 --expose
- Create a nginx pod and corresponding service, running on port 80 with label app=backend. Check connectivity through a temporary busybox image.
kubectl run backend --image=nginx --port=80 -l="app=backend" --expose
kubectl run servicecheck --image=busybox --rm --restart=Never -it -- /bin/sh -c "wget -o- http://10.101.94.246:80"
- For the backend pod created above, create another service backend-node of type NodePort. check connectivity within cluster and through node.
kubectl expose pod/backend --name=backend-node-service --port=80 --type=NodePort
kubectl run tmp --image=busybox --restart=Never --rm -it --command -- /bin/sh -c "wget -o- http://10.104.45.103:80"
wget -o- http://172.17.0.2:32172
- Create a network policy to block incoming traffic to app=backend labeled pods
References in kubernetes.io