This is a collection of scenarios that we use to simulate kubernetes' networking to know core kubernetes' components to support various communication types
To support on this we are going to deploy:
- 1 cluster has 3 nodes (1 master + 2 workers): use the
docker's kubernetes built-inwith cluster type =kindor we can create your customized cluster if we want - 2 pods
pod1: has two containerspod2: Temporary pod like one-shot pod run to verify and delete after that
- Create configmap
nginx-config
kubectl apply -f configmap.yaml- Deploy pod 1 with 2 containers
nginx: serve default http request to response http status code 200busybox: test connection to container nginx in pod 1 via ping commandping -c 3 localhost:3000
kubectl apply -f pod1-deployment.yaml- Check log of
busyboxcontainer to see the result success reaching3 packets transmitted, 3 packets received, 0% packet loss
# get pods for a namespace to retrieve the target pod
kubectl get pod -n <target-namespace>
# retrieve logs of a container on target pod
kubectl logs <target-pod-name> busybox- Retrieve target pod1's IP address
kubectl get pods -n <target-namespace> -o wide- Create a
tmp-pingerpod
# ping to `pod1` based on the output from ip ddress above
kubectl run tmp-pinger --image busybox -it --rm -- ping -c 3 <target-pod-ip-address>- Or
tmp-curler
# retrieve the data from `pod1` by sending curl request o the output from ip ddress above
kubectl run tmp-curler --image=curlimages/curl --rm -i --tty --restart=Never -- curl <http://<target-pod-ip-address>:80>- Create service to eliminate ephemeral IP address when pod is restarted, scaled or deployed
kubectl apply -f service.yaml- Create a new temporary pod
tmp-curlerto retrieve the data frompod1via curl request via static namenginx-service
kubectl run tmp-curler --image=curlimages/curl --rm -i --tty --restart=Never -- curl http://nginx-service:80- [Optional] we can restart deployment to see the new pod's Ip address was changed and perform the above command to see how service helps to abstract this change
kubectl rollout restart deployment.apps/pod1-deployment- Expose the docker container port e.g. 8081
kubectl port-forward service/nginx-service 8081:80- Retrieve the data from
pod1either accessing via browser address localhost:8081 orcurl http://localhost:8081
- Create a ingress to expose to external clients
kubectl apply -f ingress.yaml-
Add the record
127.0.0.1 kube-networking.localto your hosts e.g./etc/hosts -
Retrieve the data from
pod1via ingress customized domainkube-networking.localeither accessing via browser orcurlrequest to thehttp://kube-networking.local
kubectl get pods -n <target-namespace> -o widekubectl exec -it <target-pod-name> -n <target-namespace> -- netstat -tulnkubectl get networkpolicy -n default[Optional] If we use the docker's kubernetes built-in. We can create with the following command
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.15.1/deploy/static/provider/cloud/deploy.yaml