Explore Courses
course iconScrum AllianceCertified ScrumMaster (CSM) Certification
  • 16 Hours
Best seller
course iconScrum AllianceCertified Scrum Product Owner (CSPO) Certification
  • 16 Hours
Best seller
course iconScaled AgileLeading SAFe 6.0 Certification
  • 16 Hours
Trending
course iconScrum.orgProfessional Scrum Master (PSM) Certification
  • 16 Hours
course iconScaled AgileSAFe 6.0 Scrum Master (SSM) Certification
  • 16 Hours
course iconScaled Agile, Inc.Implementing SAFe 6.0 (SPC) Certification
  • 32 Hours
Recommended
course iconScaled Agile, Inc.SAFe 6.0 Release Train Engineer (RTE) Certification
  • 24 Hours
course iconScaled Agile, Inc.SAFe® 6.0 Product Owner/Product Manager (POPM)
  • 16 Hours
Trending
course iconKanban UniversityKMP I: Kanban System Design Course
  • 16 Hours
course iconIC AgileICP Agile Certified Coaching (ICP-ACC)
  • 24 Hours
course iconScrum.orgProfessional Scrum Product Owner I (PSPO I) Training
  • 16 Hours
course iconAgile Management Master's Program
  • 32 Hours
Trending
course iconAgile Excellence Master's Program
  • 32 Hours
Agile and ScrumScrum MasterProduct OwnerSAFe AgilistAgile CoachFull Stack Developer BootcampData Science BootcampCloud Masters BootcampReactNode JsKubernetesCertified Ethical HackingAWS Solutions Artchitct AssociateAzure Data Engineercourse iconPMIProject Management Professional (PMP) Certification
  • 36 Hours
Best seller
course iconAxelosPRINCE2 Foundation & Practitioner Certificationn
  • 32 Hours
course iconAxelosPRINCE2 Foundation Certification
  • 16 Hours
course iconAxelosPRINCE2 Practitioner Certification
  • 16 Hours
Change ManagementProject Management TechniquesCertified Associate in Project Management (CAPM) CertificationOracle Primavera P6 CertificationMicrosoft Projectcourse iconJob OrientedProject Management Master's Program
  • 45 Hours
Trending
course iconProject Management Master's Program
  • 45 Hours
Trending
PRINCE2 Practitioner CoursePRINCE2 Foundation CoursePMP® Exam PrepProject ManagerProgram Management ProfessionalPortfolio Management Professionalcourse iconAWSAWS Certified Solutions Architect - Associate
  • 32 Hours
Best seller
course iconAWSAWS Cloud Practitioner Certification
  • 32 Hours
course iconAWSAWS DevOps Certification
  • 24 Hours
course iconMicrosoftAzure Fundamentals Certification
  • 16 Hours
course iconMicrosoftAzure Administrator Certification
  • 24 Hours
Best seller
course iconMicrosoftAzure Data Engineer Certification
  • 45 Hours
Recommended
course iconMicrosoftAzure Solution Architect Certification
  • 32 Hours
course iconMicrosoftAzure Devops Certification
  • 40 Hours
course iconAWSSystems Operations on AWS Certification Training
  • 24 Hours
course iconAWSArchitecting on AWS
  • 32 Hours
course iconAWSDeveloping on AWS
  • 24 Hours
course iconJob OrientedAWS Cloud Architect Masters Program
  • 48 Hours
New
course iconCareer KickstarterCloud Engineer Bootcamp
  • 100 Hours
Trending
Cloud EngineerCloud ArchitectAWS Certified Developer Associate - Complete GuideAWS Certified DevOps EngineerAWS Certified Solutions Architect AssociateMicrosoft Certified Azure Data Engineer AssociateMicrosoft Azure Administrator (AZ-104) CourseAWS Certified SysOps Administrator AssociateMicrosoft Certified Azure Developer AssociateAWS Certified Cloud Practitionercourse iconAxelosITIL 4 Foundation Certification
  • 16 Hours
Best seller
course iconAxelosITIL Practitioner Certification
  • 16 Hours
course iconPeopleCertISO 14001 Foundation Certification
  • 16 Hours
course iconPeopleCertISO 20000 Certification
  • 16 Hours
course iconPeopleCertISO 27000 Foundation Certification
  • 24 Hours
course iconAxelosITIL 4 Specialist: Create, Deliver and Support Training
  • 24 Hours
course iconAxelosITIL 4 Specialist: Drive Stakeholder Value Training
  • 24 Hours
course iconAxelosITIL 4 Strategist Direct, Plan and Improve Training
  • 16 Hours
ITIL 4 Specialist: Create, Deliver and Support ExamITIL 4 Specialist: Drive Stakeholder Value (DSV) CourseITIL 4 Strategist: Direct, Plan, and ImproveITIL 4 Foundationcourse iconJob OrientedData Science Bootcamp
  • 6 Months
Trending
course iconJob OrientedData Engineer Bootcamp
  • 289 Hours
course iconJob OrientedData Analyst Bootcamp
  • 6 Months
course iconJob OrientedAI Engineer Bootcamp
  • 288 Hours
New
Data Science with PythonMachine Learning with PythonData Science with RMachine Learning with RPython for Data ScienceDeep Learning Certification TrainingNatural Language Processing (NLP)TensorflowSQL For Data Analyticscourse iconIIIT BangaloreExecutive PG Program in Data Science from IIIT-Bangalore
  • 12 Months
course iconMaryland UniversityExecutive PG Program in DS & ML
  • 12 Months
course iconMaryland UniversityCertificate Program in DS and BA
  • 31 Weeks
course iconIIIT BangaloreAdvanced Certificate Program in Data Science
  • 8+ Months
course iconLiverpool John Moores UniversityMaster of Science in ML and AI
  • 750+ Hours
course iconIIIT BangaloreExecutive PGP in ML and AI
  • 600+ Hours
Data ScientistData AnalystData EngineerAI EngineerData Analysis Using ExcelDeep Learning with Keras and TensorFlowDeployment of Machine Learning ModelsFundamentals of Reinforcement LearningIntroduction to Cutting-Edge AI with TransformersMachine Learning with PythonMaster Python: Advance Data Analysis with PythonMaths and Stats FoundationNatural Language Processing (NLP) with PythonPython for Data ScienceSQL for Data Analytics CoursesAI Advanced: Computer Vision for AI ProfessionalsMaster Applied Machine LearningMaster Time Series Forecasting Using Pythoncourse iconDevOps InstituteDevOps Foundation Certification
  • 16 Hours
Best seller
course iconCNCFCertified Kubernetes Administrator
  • 32 Hours
New
course iconDevops InstituteDevops Leader
  • 16 Hours
KubernetesDocker with KubernetesDockerJenkinsOpenstackAnsibleChefPuppetDevOps EngineerDevOps ExpertCI/CD with Jenkins XDevOps Using JenkinsCI-CD and DevOpsDocker & KubernetesDevOps Fundamentals Crash CourseMicrosoft Certified DevOps Engineer ExperteAnsible for Beginners: The Complete Crash CourseContainer Orchestration Using KubernetesContainerization Using DockerMaster Infrastructure Provisioning with Terraformcourse iconTableau Certification
  • 24 Hours
Recommended
course iconData Visualisation with Tableau Certification
  • 24 Hours
course iconMicrosoftMicrosoft Power BI Certification
  • 24 Hours
Best seller
course iconTIBCO Spotfire Training
  • 36 Hours
course iconData Visualization with QlikView Certification
  • 30 Hours
course iconSisense BI Certification
  • 16 Hours
Data Visualization Using Tableau TrainingData Analysis Using Excelcourse iconEC-CouncilCertified Ethical Hacker (CEH v12) Certification
  • 40 Hours
course iconISACACertified Information Systems Auditor (CISA) Certification
  • 22 Hours
course iconISACACertified Information Security Manager (CISM) Certification
  • 40 Hours
course icon(ISC)²Certified Information Systems Security Professional (CISSP)
  • 40 Hours
course icon(ISC)²Certified Cloud Security Professional (CCSP) Certification
  • 40 Hours
course iconCertified Information Privacy Professional - Europe (CIPP-E) Certification
  • 16 Hours
course iconISACACOBIT5 Foundation
  • 16 Hours
course iconPayment Card Industry Security Standards (PCI-DSS) Certification
  • 16 Hours
course iconIntroduction to Forensic
  • 40 Hours
course iconPurdue UniversityCybersecurity Certificate Program
  • 8 Months
CISSPcourse iconCareer KickstarterFull-Stack Developer Bootcamp
  • 6 Months
Best seller
course iconJob OrientedUI/UX Design Bootcamp
  • 3 Months
Best seller
course iconEnterprise RecommendedJava Full Stack Developer Bootcamp
  • 6 Months
course iconCareer KickstarterFront-End Development Bootcamp
  • 490+ Hours
course iconCareer AcceleratorBackend Development Bootcamp (Node JS)
  • 4 Months
ReactNode JSAngularJavascriptPHP and MySQLcourse iconPurdue UniversityCloud Back-End Development Certificate Program
  • 8 Months
course iconPurdue UniversityFull Stack Development Certificate Program
  • 9 Months
course iconIIIT BangaloreExecutive Post Graduate Program in Software Development - Specialisation in FSD
  • 13 Months
Angular TrainingBasics of Spring Core and MVCFront-End Development BootcampReact JS TrainingSpring Boot and Spring CloudMongoDB Developer Coursecourse iconBlockchain Professional Certification
  • 40 Hours
course iconBlockchain Solutions Architect Certification
  • 32 Hours
course iconBlockchain Security Engineer Certification
  • 32 Hours
course iconBlockchain Quality Engineer Certification
  • 24 Hours
course iconBlockchain 101 Certification
  • 5+ Hours
NFT Essentials 101: A Beginner's GuideIntroduction to DeFiPython CertificationAdvanced Python CourseR Programming LanguageAdvanced R CourseJavaJava Deep DiveScalaAdvanced ScalaC# TrainingMicrosoft .Net Frameworkcourse iconSalary Hike GuaranteedSoftware Engineer Interview Prep
  • 3 Months
Data Structures and Algorithms with JavaScriptData Structures and Algorithms with Java: The Practical GuideLinux Essentials for Developers: The Complete MasterclassMaster Git and GitHubMaster Java Programming LanguageProgramming Essentials for BeginnersComplete Python Programming CourseSoftware Engineering Fundamentals and Lifecycle (SEFLC) CourseTest-Driven Development for Java ProgrammersTypeScript: Beginner to Advanced
  • Home
  • Blog
  • Devops
  • What are Kubernetes Pods? Types, Examples, Best Practices

What are Kubernetes Pods? Types, Examples, Best Practices

By Mayank Modi

Updated on Nov 05, 2022 | 9 min read

Share:

Kubernetes (sometimes shortened to K8s with the 8 standing for the number of letters between the “K” and the “s”) is an open-source system to deploy, scale, and manage containerized applications anywhere. Kubernetes is a container-centric management software that allows the creation and deployment of containerized applications with ease. In Kubernetes, Pods are the fundamental building blocks. They are the smallest deployable units that can create and manage. 

Originally created by Google Cloud in 2014, Kubernetes is now being offered by leading Cloud Providers like AWS and Azure. In this article, we are going to have a look into the working of Kubernetes and the creation of Kubernetes Pods for the deployment of applications.  

What are Kubernetes Pods?

Pods are the smallest execution unit in Kubernetes. As the official Documentation says “A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.”

For example, Let's assume that we have 5 containers ready for Kubernetes deployment. We can put all 5 containers in the same pod if all of them have to be run with the same configuration or we can divide the containers based on their purpose and load management.

Pods can also persist volumes just like docker, and they can be easily configured based on the requirement. Each Pod is tied to the Node where it is scheduled and remains there until termination (according to restart policy) or deletion. In case of a Node failure, identical Pods are scheduled on other available Nodes in the cluster.

If you're looking to learn about the basic of Kubernetes, you can refer our video on Kubernetes Architecture

Types of Kubernetes Pods 

There are two types of pods in Kubernetes namely single container pod and multi container pod. 

1. Single Container Pod

As the name suggests, if there is only a single container running in the Kubernetes pod, then it is called a single container pod and it can easily be created with the help of a YAML file. Here is a sample YAML file used to create a pod with the postgres database.

apiVersion: v1 
kind: Pod 
metadata: 
name: Postgres 
spec: 
containers: 
- name: Postgres 
image: Postgres: 3.1 
ports: 
containerPort: 8000 
imagePullPolicy: Always 

2. Multi Container Pod

In this type of pod, we can run multiple containers within a single pod. It can be created by specifying the containers in the same YAML file. Here is a sample YAML file used to create a multi container Pod with Tomcat and MongoDB images.

apiVersion: v1 
kind: Pod 
metadata: 
name: Tomcat 
spec: 
containers: 
- name: Tomcat 
image: tomcat: 8.0 
ports: 
containerPort: 7500 
imagePullPolicy: Always 
-name: Database 
Image: mongoDB 
Ports: 
containerPort: 7501 
imagePullPolicy: Always 

Other than the number of containers running in the pod, there is no difference between a single-container pod and a multi-container pod. 

How to Create a Pods in Kubernetes? 

In order to create a pod, we need to create a Kubernetes cluster in which we can have multiple pods based on the requirement. The clusters can also be scaled horizontally as well as vertically based on the workload. There is also an option of autoscaling based on the incoming load. Clusters are basically a set of nodes that run docker applications. 

The application needs to dockerized with its own set of requirements and necessary services to keep it running. When compared to virtual machines, these are much more flexible and lightweight.

Clusters should at least have a master node, and they can have any number of worker nodes. The master node controls the entire cluster and monitors the activity, logs and metrics related to the cluster. To create a Kubernetes pod, we must create a Kubernetes cluster with the necessary configurations. A pod can be created on top of the Kubernetes cluster only. To create a pod, we must configure the yaml file according to the requirements. Here is a sample yaml file.

apiVersion: v1 
kind: Pod 
metadata: 
  name: nginx 
spec: 
  containers: 
  - name: nginx 
    image: nginx:1.14.2 
    ports: 
    - containerPort: 80 
  • Apiversion: This field can be used to denote the version of the service that is being deployed in Kubernetes. 
  • Kind: This is usually the kind of deployment in Kubernetes. In this case, the container is being deployed in a pod. 
  • Metadata: This field is used to configure other metadata of the container that is being deployed in K8s. 
  • Spec: This field is used to configure the settings of pod and the port that should be used to deploy the service in K8s. 

Command :

kubectl create -f manifests/rs-example.yaml   

The main difference between create and apply commands in K8s is that create is used as a declarative state like defining the pod whereas create command in K8s is used to implement the state that has been declared. 

Creates the pod with the above configurations mentioned in the YAML file. 

To check if the Pod is running in the Kubernetes cluster: 

Command:

kubectl get pods --watch --show-labels 

Learn more about DevOps and writing pipelines with the Best DevOps Courses Online.

How to View a Kubernetes Pod? 

To view all the pods running in a Kubernetes cluster, we can use the following command:

Command

kubectl get pods  

This command will list all the pods running in a particular Kubernetes cluster. 

To get the pod configuration we can use the following command 

Command

kubectl describe pod  

This command will list the nginxconfiguration along with the pod configuration details.

How to Implement Kubernetes Pod Policy?

A Pod Security Policy defines a set of conditions a pod must run with in order to run on the cluster. These conditions span host-level access, to a range of UIDs a container can run as, and even what volumes a pod can use.
All the policies are configurable in the yaml file used to create a pod. The Yaml file can be used to implement various rules and policies over the Kubernetes pod. 

Here is a sample yaml file which implements policies over the pod.

apiVersion: policy/v1beta1 
kind: PodSecurityPolicy 
metadata: 
name: my-restricted-psp 
spec: 
privileged: false 
# Required to prevent escalations to root. 
allowPrivilegeEscalation: false 
# Allow core volume types. 
volumes: 
- 'configMap' 
- 'emptyDir' 
 - 'projected' 
 - 'secret' 
- 'downwardAPI' 
 - 'nfs' 
- 'persistentVolumeClaim' 
 - 'awsElasticBlockStore' 
hostNetwork: false 
hostIPC: false 
hostPID: false 
runAsUser: 
# Require the container to run without root privileges. 
 rule: 'RunAsAny' 
seLinux: 
 # This policy assumes the nodes are using AppArmor rather than SELinux. 
 rule: 'RunAsAny' 
 supplementalGroups: 
 rule: 'MustRunAs' 
ranges: 
# Forbid adding the root group. 
- min: 1 
max: 65535 
 fsGroup: 
rule: 'MustRunAs' 
ranges: 
# Forbid adding the root group. 
- min: 1 
max: 65535 
 readOnlyRootFilesystem: false 

To see what security policy your pod is using, you can type in the following command in the terminal.

kubectl describe <pod-name> -n <your-namespace> 

You can refer to the following documentation for the types of policies that can be implemented over a Kubernetes pod. 

How to Destroy Kubernetes Pod? 

It is also important to delete or kill the pods which are not used anymore in the Kubernetes cluster. The following command kills the pod present in the Kubernetes cluster. 

Command

kubectl delete pod <pod-name> 

After executing the above command, you will get  pod <pod-name> deleted. This confirms that the pod has been successfully deleted in the Kubernetes cluster. 

Labels 

Labels are usually key value pairs that are attached in the yaml file to identify and indicate to the end user that this pod hosts certain kind of service. Its usually in the meta data section of the yaml file.

"metadata": { 
  "labels": { 
    "key1" : "value1", 
    "key2" : "value2" 
  } 
} 

Kubernetes Pods Best Practices for Security, Reliability and Resource Requests 

It is important to know some of the best practices that engineers follow when it comes to Kubernetes. 

  • Understand and embrace the ephemeral nature of Kubernetes. 
  • Avoid single points of failure. 
  • Set resource requests and limits for CPU and memory. 
  • Use liveness and readiness probes.

It is also necessary to configure the pods according to the requirement to save costs if its running in a managed instance and to optimize computations. 

To read more about Kubernetes and deployment, you can refer to the best Kubernetes course online

Conclusion

Kubernetes Pods are the essential building blocks of containerized applications in Kubernetes. In this blog, we have discussed the basics of Kubernetes and stepping slowly to understand Kubernetes pods, the steps to create a pod as well as to monitor pods in a Kubernetes cluster. We have also covered some of the best practices of Kubernetes followed in the DevOps world.

Enrolling to the Best Docker and Kubernetes Course at the right time can boost your DevOps career. You can also refer to the following resources to know more about K8s.

Frequently Asked Questions (FAQs)

1. How many ways can we create pods in Kubernetes?

2. What is the difference between POD and container?

3. What is the difference between POD and node?

4. Can we run two containers in a pod?

Mayank Modi

86 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

Suggested Blogs