Pods and Containers - Kubernetes Networking | Container Communication inside the Pod

TechWorld with Nana · Beginner ·☁️ DevOps & Cloud ·6y ago

Key Takeaways

Explains container communication inside Kubernetes pods using Docker containers

Full Transcript

in kubernetes the smallest unit or component is a pot and not a container and considering that pot always contains one main container for example you might have a pot with post Chris container or elasticsearch container or your own application some people may be asking why the need for abstracting the container with a pot if there is any way it's just one main application running inside so in this video I'm gonna explain to you why having a pot is an abstraction over container is such an important concept in kubernetes I'm gonna give you a comparison between pod and container and I will show you in which cases you would need to have multiple containers inside one pot and how these containers then will communicate with each other and its core kubernetes networking has one important fundamental concept which is that every pot has a unique IP address and that IP address is reachable from all the other pots in the cluster so that's the main concept now why is it important and valuable to have this pod component with its own IP address you see one main challenge on distributed infrastructure with multiple servers is how to allocate ports to services and applications running on servers without getting conflicts since obviously you can only allocate one port once on a single host with containers you would soon face this challenge because this is how container port mapping works let's say for example a PostgreSQL container where inside the container the Postgres application starts at port 5 4 3 2 now when you start containers directly on your machine what you do is you bind your host port to the application port in the container and you see that in practice we can start post-race docker container so this is the part where we map or we bind the port on the host to the port of the application running inside the docker container so it doesn't have to be the same port I can also give it a completely different one so let's write 5,000 and if I execute this command Postgres container started and if we check here with dr. PS I will see that port 5000 on the host machine is mapped to this one here so now the application is reachable by the host port now that I have one Postgres already running I could start another post-course container that will also run at the same port but bind it on a different port on my host so this will work as well so if I go here now and say dr. PS I will see two possible applications bound to different ports on the host and this is how containers work the problem with this is when you have hundreds of containers running on your servers how can you keep track of what ports are still free on the host to bind them so soon enough with this type of port allocation it will become difficult to have an overview and the way kubernetes solves this problem is by abstracting the containers using pots where pot is like its own small machine with its own IP address usually with one main container running inside for example you might have a pot where Postgres container is running when a pot is created on a node it gets its own network namespace and a virtual Ethernet connection to connect it to the underlying infrastructure network so a pot is a host just like your laptop both have IP addresses and a range of ports they can allocate to its containers this means you don't have to worry about port mappings on the server where pot is running and all inside the pot itself but since you anyways usually have just one main container or sometimes maybe maximum up to six containers inside a pot you won't get conflicts there because you have a pretty good overview of what containers are running inside this means that on one server you can have for example 10 micro service applications that all run on port 8080 inside 10 different pots and you won't have any conflicts because they all run on self-contained isolated machines which are pots so to also see that in practice I have a mini Q cluster running so I'm gonna create a pod that's gonna run a Postgres container inside so this is the pods yamo file that I'm gonna execute this is the same image the same environmental variable and this is the port here so I'm just defining the container port which is where the application inside the container is gonna start it so I'm gonna go and execute this file and by the way if you want to learn how to setup and use mini Cube on your laptop I have a separate video about that where I explain all the details of how to set it up together with the cube CTL command lines so you can check that out and the pod was created and the Postgres is running so now if I wanted to run multiple Postgres pots on one node I can I can do that too so I'm gonna change name here so I'm gonna say Postgres to this and we'll leave the container name we're just going to change the pod name and everything else stays the same so I'm gonna apply that again and Postgres to was created so now I'll have two pots running the same application and I can create tens of those and this is a normal case for example we have a multiple replicas of the same application running on your server and there's no problem of port mapping here another reason why pod abstraction over container is useful is that you can easily replace the container runtime in kubernetes so for example if you replace docker run time with another container runtime like vagrant for example kubernetes configuration will stay the same because it's all on the pod level it means that kubernetes isn't tied up to any particular container runtime implementation now as I mentioned at the beginning sometimes pod might have two or more containers inside this is a case when you need to run a helper or side application to your main application like for example for synchronizing when you have multiple database pots or for baking up your application it certain intervals so would have this back up side car container within your application container or it could be a scheduler or maybe authentication gateway so there are many use cases where you might end up having more than one containers inside a pod now the question is how do these containers communicate with each other inside the pot remember pod is an isolated virtual host with its own network namespace and containers inside all run in this network namespace this means that containers can talk to each other via localhost and a port number just like when you're running multiple applications on your own laptop so let's also see that in practice so I'm gonna head over to my mini cube cluster and create a pod with two containers so I'm gonna take nginx for that so that we can curl the endpoint so I'm gonna have one nginx container and inside that in the containers part I'm gonna add another container and this is going to be just a simple curl image because this one has curl inside and also netstat because most of the images do not come with curl or netstat and these kind of tools to keep them as lightweight as possible and this is just gonna print out something and then wait for 300 seconds so that we have enough time to check the endpoint so I'm gonna save that you can find the link to the yellow file in the description so that you can try it out yourself and let's create that pod Phoenix well and pod gets created so let's check that and both of the containers are running and now I'm going to enter into curl container so I'm gonna do that pod name and now because I have two containers I have to specify the container name where I want to enter so it's gonna be sidecar container so I'm inside the curl container so what I'm gonna do here is I'm gonna check first with net stud and this is the port where nginx is running so this is the 80 port and I can also curl localhost 80 and I'll get this welcome to nginx index.html page and if I check the nginx logs I'm gonna see the those curl requests coming also from localhost from the curl container also having notice that in the kubernetes cluster when you run docker containers there is this post container always per each pot these are called send box containers whose only job is to reserve and hold the pots network namespace that's shared by all the containers in a pot so post container makes it possible for the containers to communicate with each other and also if a container dies and a new one gets created pot will stay and keep its IP address but know that if the pot itself dies it gets recreated and a new pot will get assigned a different IP address so to see that pulse container let's go back to the mini cube cluster however note that mini cube runs in a virtual machine so if I do docker PS here I won't see any containers running inside the mini cube cluster because it's not on my hosts it's running in its own virtual host so in order to connect to it from my hosts what I have to do is tell my daugher to execute docker commands on a remote host which is gonna be my mini cube and for that there is this compact comments so if I echo this which is mini cube docker and you see that I set a docker host which basically sets a remote host address for my daugher client and this is the IP address of the mini cube you can check that address by the way if you for example describe a pod here you see in this meta information note is set mini cube and this is the IP address that I have here and it also sets a certificate so that you can access that so now if I do this and then dr. PS I will be able to see all the docker containers that are running in the mini cube so here even though I just created one engine X pod with two containers in it I get a whole list of containers so where this come from is basically in my mini cube I have this default namespaces as well that have their own containers running if you want to learn about namespaces I have a separate video about that so you can check that out so let's go back here notice they're a bunch of post containers here and if I grab that based using these prefix I see the list of post containers and in the name they all have pod name that they belong to so let's let's clear this up and let's check for nginx pod and here it is this is our nginx pot this is nginx ingress controller that is also running in a different namespace so this is our pod right here and it has its pause container so every pod has its own pause container now this video just showed one part of the whole kubernetes networking which is a much broader topic so for example other concepts would include things like how pots themselves communicate with each other across hundreds of servers regardless of which nodes they are on also the concept of how the outside world communicates with communities cluster as well as how kubernetes plugs into the underlying infrastructure network which can be a cloud platform or a bare-metal infrastructure and in addition to that I believe that learning about docker container networking will really help in understanding how kubernetes networking works because then you have a good comparison so because there are so many concepts there I'm creating a complete kubernetes networking course where I explain all these concepts with real-life example demos and once I release that course I will announce it on my channel so stay tuned for that if you liked this video and got some valuable information out of it then please like and subscribe for more videos like this and also click the notification bell if you don't want to miss new video uploads thanks for watching and see you in the next video

Original Description

Kubernetes Networking | Kubernetes Container Networking | Kubernetes Pods and Containers | Kubernetes Container Communication | Kubernetes Container Port ► Subscribe To Me On Youtube: https://bit.ly/2z5rvTV In this video I cover one part of the broader Kubernetes Networking topic, which is container communication inside pods. Considering Pods mostly contain only 1 main container, I start by answering the question of why having a Pod as an abstraction over container is such an important concept in Kubernetes. I show how container port mapping is a problem with hundreds of containers, specifically how to allocate ports without getting conflicts. How this compares to Pods and how Pods solve this port allocation problem. In addition, I show you in which cases you would need to run multiple containers in one pod and how these containers communicate with each other inside this pod. ❌ Correction for 6:15 in the video: Vagrant is NOT a container runtime alternative. K8s lists some of the alternatives here ► https://kubernetes.io/docs/setup/production-environment/container-runtimes/. ▬▬▬▬▬▬ Complete Kubernetes Networking Course 🎬: I'm making a complete course about Kubernetes Networking, covering rest of the topics, like ► how pods communicate with each other on the same node and across hundreds of servers? ► how does the outside world communicate with K8s cluster? ► how K8s cluster plugs into the underlying infrastructure network? ► Docker Container Networking ▬▬▬▬▬▬ T I M E S T A M P S 0:00 - Intro 0:46 - Pod - fundamental concept 1:05 - Problem with Container Port Mapping WITHOUT Pod 4:15 - Solution - Pod abstraction 6:28 - When do we need multiple containers in a pod? Side-car containers 7:08 - How do containers in a pod communicate to each other? 9:30 - pause or sandbox container 12:27 - Kubernetes Networking Topics Overview ► Reference to demo YAML Configs: https://gitlab.com/nanuchi/kubernetes-tutorial-series-youtube/-/tree/master/container-communication-k8s-n
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from TechWorld with Nana · TechWorld with Nana · 41 of 60

1 What is Docker? Docker container concept explained || Docker Tutorial 1
What is Docker? Docker container concept explained || Docker Tutorial 1
TechWorld with Nana
2 What is a Docker Container? Docker Demo || Docker Tutorial 2
What is a Docker Container? Docker Demo || Docker Tutorial 2
TechWorld with Nana
3 How to install docker? Step by Step || Docker Tutorial 3
How to install docker? Step by Step || Docker Tutorial 3
TechWorld with Nana
4 8 Basic Docker Commands || Docker Tutorial 4
8 Basic Docker Commands || Docker Tutorial 4
TechWorld with Nana
5 Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
TechWorld with Nana
6 Docker vs Virtual Machine | simply explained || Docker Tutorial 6
Docker vs Virtual Machine | simply explained || Docker Tutorial 6
TechWorld with Nana
7 Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
TechWorld with Nana
8 Developing with Docker - Docker in Practice || Docker Tutorial 8
Developing with Docker - Docker in Practice || Docker Tutorial 8
TechWorld with Nana
9 Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
TechWorld with Nana
10 Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
TechWorld with Nana
11 Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
TechWorld with Nana
12 Docker Volumes explained in 6 minutes
Docker Volumes explained in 6 minutes
TechWorld with Nana
13 Deploying the containerized application with Docker Compose || Docker Tutorial 12
Deploying the containerized application with Docker Compose || Docker Tutorial 12
TechWorld with Nana
14 Docker Volumes Demo || Docker Tutorial 13
Docker Volumes Demo || Docker Tutorial 13
TechWorld with Nana
15 Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
TechWorld with Nana
16 What is Kubernetes | Kubernetes explained in 15 mins
What is Kubernetes | Kubernetes explained in 15 mins
TechWorld with Nana
17 Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
TechWorld with Nana
18 Kubernetes Architecture explained | Kubernetes Tutorial 15
Kubernetes Architecture explained | Kubernetes Tutorial 15
TechWorld with Nana
19 Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
TechWorld with Nana
20 Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
TechWorld with Nana
21 Top 3 programming languages to learn in 2020 | meta analysis
Top 3 programming languages to learn in 2020 | meta analysis
TechWorld with Nana
22 Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
TechWorld with Nana
23 Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
TechWorld with Nana
24 Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
TechWorld with Nana
25 Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
TechWorld with Nana
26 Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
TechWorld with Nana
27 Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
TechWorld with Nana
28 Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
TechWorld with Nana
29 Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
TechWorld with Nana
30 Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
TechWorld with Nana
31 Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
TechWorld with Nana
32 Kubernetes Ingress Tutorial for Beginners | simply explained  | Kubernetes Tutorial 22
Kubernetes Ingress Tutorial for Beginners | simply explained | Kubernetes Tutorial 22
TechWorld with Nana
33 What is Helm in Kubernetes? Helm and Helm Charts explained  | Kubernetes Tutorial 23
What is Helm in Kubernetes? Helm and Helm Charts explained | Kubernetes Tutorial 23
TechWorld with Nana
34 How Websites Work | simply explained with examples
How Websites Work | simply explained with examples
TechWorld with Nana
35 What is JavaScript? | JavaScript Tutorial #1
What is JavaScript? | JavaScript Tutorial #1
TechWorld with Nana
36 What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
TechWorld with Nana
37 JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
TechWorld with Nana
38 How Prometheus Monitoring works | Prometheus Architecture explained
How Prometheus Monitoring works | Prometheus Architecture explained
TechWorld with Nana
39 Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
TechWorld with Nana
40 JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
TechWorld with Nana
Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
TechWorld with Nana
42 Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
TechWorld with Nana
43 Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
TechWorld with Nana
44 Pull Image from Private Docker Registry in Kubernetes cluster | Demo
Pull Image from Private Docker Registry in Kubernetes cluster | Demo
TechWorld with Nana
45 Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
TechWorld with Nana
46 Yaml Tutorial | Learn YAML in 18 mins
Yaml Tutorial | Learn YAML in 18 mins
TechWorld with Nana
47 Terraform explained in 15 mins | Terraform Tutorial for Beginners
Terraform explained in 15 mins | Terraform Tutorial for Beginners
TechWorld with Nana
48 Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
TechWorld with Nana
49 Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
TechWorld with Nana
50 Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
TechWorld with Nana
51 Kubernetes Operator simply explained in 10 mins
Kubernetes Operator simply explained in 10 mins
TechWorld with Nana
52 What is Infrastructure as Code? Difference of Infrastructure as Code Tools
What is Infrastructure as Code? Difference of Infrastructure as Code Tools
TechWorld with Nana
53 AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
TechWorld with Nana
54 Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
TechWorld with Nana
55 GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
TechWorld with Nana
56 Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
TechWorld with Nana
57 Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
TechWorld with Nana
58 Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
TechWorld with Nana
59 Containers on AWS Overview: ECS | EKS | Fargate | ECR
Containers on AWS Overview: ECS | EKS | Fargate | ECR
TechWorld with Nana
60 Kubernetes is dropping Docker support - What does it mean for YOU?
Kubernetes is dropping Docker support - What does it mean for YOU?
TechWorld with Nana

Related AI Lessons

Qwen 3.6 27B Is the Local Dev Sweet Spot — Here's Why
Discover why Qwen 3.6 27B is the ideal choice for local development, and how it can boost your productivity
Dev.to · Carter May
Deploying Spring Petclinic Microservices with Docker Compose: An End-to-End DevOps Deployment Experience
Learn to deploy Spring Petclinic microservices with Docker Compose for a seamless DevOps experience
Dev.to · Nice Nwogu
Qwen 3.6 27B Is the Local Dev Sweet Spot — Here's Why
Discover why Qwen 3.6 27B is the ideal choice for local development, offering a sweet spot for efficiency and performance
Dev.to · Carter May
Terraform Seems Annoying. But It’s Just Saving You.
Learn how Terraform's 'saved plan is stale' errors are actually a safety feature to prevent unintended changes to your infrastructure
Medium · DevOps

Chapters (8)

Intro
0:46 Pod - fundamental concept
1:05 Problem with Container Port Mapping WITHOUT Pod
4:15 Solution - Pod abstraction
6:28 When do we need multiple containers in a pod? Side-car containers
7:08 How do containers in a pod communicate to each other?
9:30 pause or sandbox container
12:27 Kubernetes Networking Topics Overview
Up next
Containers on Amazon ECS with Mama J
AWS Developers
Watch →