Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

K8s Pods

Posted on Aug 13 As previously discussed k8s provide us with the following features: In k8s the lowest level of deployment is pod. If we compare this to docker, In docker we deploy the containers.In Docker we used to create a Container and we deploy that container but, in k8s we cannot directly deploy the container, in k8s we will use these containers but as a pod.So, now you may be thinking What is pod? and why we should deploy our container as a pod?hold let me explain you, In docker, if we want to run a continer we execute,docker run -d -it --name containerImae -p x:x ImageName. In this command you can see that, all of these arguments are passed in command line to run the container. Which becomes quite lengtly most of the time. Which is not much helpfulfor enterprise solution when you have a lot of containers to work with, this affects the fundamental advantage of k8s.To fix this issue, What k8s want us to do is,Write everything in a file and submit the file to the k8s component that we will learn soon.Create a yml file and mention everything inside that file. Usually the file i.e pod manifest file are called as pod.ymlIn k8s everything is writeen with yml file. If you are unfamiliar with the yml, you can follow this.So now we can say,A pod can be described as a defination of how to run a container. Pod basically is a wrapper or a concept that is similar to container but it abstracts the defined commands / arguments in pod.ymlA pod is just a wrapper over a container.its repeated twice I know but the above line is important.A pod can contain a single container or a multiple container. If pod contains multiple containers k8s provide some advantages.If you put group of container in one single pod, then k8s will allow to share networking, share resources among the containers, this way container a and container b inside a single pod can talk to each other using localhost. Which eventually explains that, there is a pod and inside that pod we have a container. k8s allocates a Cluster Ip address to the pod and you can access the application inside the pod using Pod Cluster Ip addressIp addresses are generated for the pods not the conatiner. kube-proxy which we have discussed in last post that will generate the ip address.This mug is enough about pods now, let's get some hands-one experience.In docker when ever we want to execute any command we have docker cli. Similarly in k8s we have kubectl.kubectl is command line for k8s.You can follow this guild to Install kubectlWe will use minkube for learning purpose.To Install minikube follow thisIf you dont know what is minikube, you can follow this blogIn simple words, what minikube will do is it will create a VM first, on top of this this will create a single node kubernetes cluster, one node that will act has a master node and worker node.Start minikubeGoto your notes directory and create a file pod.ymlNow the question? all these are okay, but how and what should be inside the pod.If I say you dont need to remember, what all things should be inside the pod.yml, you will be surprised, but this is the truth you should only remeber the keyword and rest you can copy from this and change as per your requirement.Slowly, when you start practicing you will automatically learn all the required args.In page mentioned above, you can see a code snippet like thisThis is the snippet or pod manifest, which will create a nginx container.Let's understand the manifest line by line apiVersion: v1 -> This indicates that the configuration is using the Kubernetes API version 1.kind: Pod -> This specifies that you are creating a Pod.metadata -> This section contains metadata about the Pod, such as its name.name -> This assigns the name "nginx" to the Pod.spec -> The "spec" section defines the desired state of the Pod.containers -> This is where you define the containers that will run inside the Pod. In this case, there is one container definition.name: nginx -> This assigns the name "nginx" to the container.image: nginx:1.14.2 -> This specifies the Docker image to be used for the container. In this case, it's the official Nginx image with version 1.14.2.ports -> This section defines the ports that the container will listen on.containerPort: 80 -> This specifies that the container will listen on port 80. This is the standard port for HTTP traffic, which is commonly used for web servers like Nginx.Now, running/executing the pod fileCheck status of the podsNow, as you can see the STATUS of the pods is running and NAME is nginx as mentioned in the yml file and the Ip address is also assigned to the pod.But, to access that we need to login into minikube cluster.As in our case minikube is the Master node we need to login into the minikube but in production you will need to login into your master node that can be an ec2 instance or anything.To access the applicationVerify the applicationYou can check all the kubectl commands, here at kubectl cheetsheetOn top of the pod we have a wrapper called deployment. So, we have to use deployment to use the features like auto healing and auto scaling.In production, we will not deploy pods we will deploy deployments.If you have interest in open source you can contribue to my projects If the article helps you, leave a like, follow, or anything 🙂.You can follow me on LinkedIn, GitHub, Dev.to and hashnode.ByeTemplates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Harish Aravindan - Jul 16 Pratik Singh - Jul 24 Doğukan Eren - Jul 25 Kirill Balakhonov - Jul 24 Once suspended, scorcism will not be able to comment or publish posts until their suspension is removed. Once unsuspended, scorcism will be able to comment and publish posts again. Once unpublished, all posts by scorcism will become hidden and only accessible to themselves. If scorcism is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Abhishek Pathak. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag scorcism: scorcism consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging scorcism will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

K8s Pods

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×