Kubernetes Networking Visualized
Kubernetes Networking addresses four concerns:
- Containers within a pod use networking to communicate via loopback.
- Cluster Networking provides communication between different pods.
- The service resources let you expose an application running in pods to be reachable from outside of your cluster.
- You can also use services to publish services only for consumption inside your cluster.
Container to Container communication on the same pod
- happens through localhost within the containers.
- Create a manifest file for creating a pod with 2 containers.
- name: c00
command: ["/bin/bash", "-c", "while true; do echo Hello; sleep 5; done"]
- name: c01
- containerPort: 80
- Apply manifest file and create a pod with 2 containers.
kubectl apply -f pod.yml
- Exec inside one container c00
kubectl get pods
kubectl exec testpod -it -c c00 -- /bin/bash
- Curl localhost:80 for communicating to container 2 from container 1
apt install curl