Kubernetes - Pods

  Pods

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

What is a Pod?

Note: While Kubernetes supports more container runtimes than just Docker, Docker is the most commonly known runtime, and it helps to describe Pods using some terminology from Docker.

The shared context of a Pod is a set of Linux namespaces, cgroups, and potentially other facets of isolation - the same things that isolate a Docker container. Within a Pod's context, the individual applications may have further sub-isolations applied.

In terms of Docker concepts, a Pod is similar to a group of Docker containers with shared namespaces and shared filesystem volumes

Using Pods

  • Pods that run a single container. The "one-container-per-Pod" model is the most common Kubernetes use case; in this case, you can think of a Pod as a wrapper around a single container; Kubernetes manages Pods rather than managing the containers directly.
  • Pods that run multiple containers that need to work together. A Pod can encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources. These co-located containers form a single cohesive unit of service—for example, one container serving data stored in a shared volume to the public, while a separate sidecar container refreshes or updates those files.

Pod networking

Each Pod is assigned a unique IP address for each address family. Every container in a Pod shares the network namespace, including the IP address and network ports. Inside a Pod (and only then), the containers that belong to the Pod can communicate with one another using localhost. When containers in a Pod communicate with entities outside the Pod, they must coordinate how they use the shared network resources (such as ports). Within a Pod, containers share an IP address and port space, and can find each other via localhost.

 

Pod Lifecycle

This page describes the lifecycle of a Pod. Pods follow a defined lifecycle, starting in the Pending phase, moving through Running if at least one of its primary containers starts OK, and then through either the Succeeded or Failed phases depending on whether any container in the Pod terminated in failure.

LAB

1.# nginx-pod.yaml

apiVersion: v1

kind: Pod

metadata:

  name: nginx-pod

  labels:

    app: nginx

    tier: dev

spec:

  containers:

  - name: nginx-container

    image: nginx

 

2. Create and display Pods

# Create and display PODs

kubectl create -f nginx-pod.yaml

kubectl get pod

kubectl get pod -o wide

kubectl get pod nginx-pod -o yaml

kubectl describe pod nginx-pod

3. Test & Delete

# To get inside the pod

kubectl exec -it nginx-pod -- /bin/sh

 

# Create test HTML page

cat <<EOF > /usr/share/nginx/html/test.html

<!DOCTYPE html>

<html>

<head>

<title>Testing..</title>

</head>

<body>

<h1 style="color:rgb(90,70,250);">Hello, DevopsWorld...!</h1>

<h2>Congratulations, you passed :-) </h2>

</body>

</html>

EOF

exit

 

# Expose PODS using NodePort service

kubectl expose pod nginx-pod --type=NodePort --port=80

 

# Display Service and find NodePort

kubectl describe svc nginx-pod

kubectl get svc

# Open Web-browser and access webapge using

http://nodeip:nodeport/test.html

# Delete pod & svc

kubectl delete svc nginx-pod

kubectl delete pod nginx-pod


Comments

Popular posts from this blog

Terraform

Different Types of Reports in Scrum - Agile

Scrum Master Interview help - Bootcamp