Kubernetes Networking Visualized

Kubernetes Networking Visualized

All about networking in Kubernetes.

ยท

2 min read

Kubernetes Networking addresses four concerns:

  1. Containers within a pod use networking to communicate via loopback.
  2. Cluster Networking provides communication between different pods.
  3. The service resources let you expose an application running in pods to be reachable from outside of your cluster.
  4. You can also use services to publish services only for consumption inside your cluster.

1_vQQSViWiDkh1X81r3n99Qw.webp

Container to Container communication on same pod

1_pyGYl93pM4b2rJ49DHgJlg.webp

  • happens through localhost within the containers.
kind: Pod
apiVersion: v1
metadata:
  name: testpod
spec:
  containers:
    - name: c00
      image: ubuntu
      command: ["/bin/bash", "-c", "while true; do echo Hello; sleep 5; done"]
    - name: c01
      image: httpd
      ports:
        - containerPort: 80
kubectl apply -f pod.yml
kubectl get pods
kubectl exec testpod -it -c c00 -- /bin/bash
  • inside the container
apt update
apt install curl
curl localhost:80

Communication between two different Pods within same machine(Node)

  • Pod to Pod communication on same worker node through Pod IP.
  • By Default Pod's IP will not be acccessible outside the node.

1_-9yFiujQtPJL1tczRDeavg.webp

  • Create 2 pods
kind: Pod
apiVersion: v1
metadata:
  name: testpod1
spec:
  containers:
    - name: c00
      image: nginx
      command: ["/bin/bash","-c","while true; do echo Hello; sleep 5; done"]
      ports:
        - containerPort: 80
kind: Pod
apiVersion: v1
metadata:
  name: testpod2
spec:
  containers:
    - name: c03
      image: httpd
      ports:
        - containerPort: 80
kubectl apply -f pod2.yml
kubectl apply -f pod3.yml
  • Check pods are running, and pods wide description
kubectl get pods
kubectl get pods -o wide
  • Inside node, run commands to get request on pods IP addresses
curl <POD_ID>:80

Did you find this article valuable?

Support KubeKode Blogs by becoming a sponsor. Any amount is appreciated!

ย