DevOps | Kubernetes Pods | Quick Introduction | Creation & Management

DevOps | Kubernetes Pods | Quick Introduction | Creation & Management

A Kubernetes pod is a group of one or more containers that are deployed together with configuration to run containers. 


Couple of Points about Pods
- Pods do not have a managed lifecycle, if they die, they will not be recreated.
- Pods are actually not only containers. 
- The hostname is set to the pod’s Name for the application containers within the pod.
- Each container in the Pod is assigned with its unique IP address.
- The individual containers may be versioned, rebuilt and redeployed independently. 
- Pods aren’t not durable entities. They won’t survive scheduling failures, node failures.
- When a pod is scaled out, all the containers within it are scaled as a group. 

  
  
Create Pod using Kubectl CLI.

In this example, we will create a Pod with name “ngnix-lab-cli” , docker image “ngnix” will be used, all container in the Pod will be exposed to the port 80 and 02 containers will be created in the Pod.

# kubectl run ngnix-lab-cli --image=nginx --port 80 --replicas=2

Below is more details on the option and configuration can be used for spin up the Pods using CLI.

Usage :
kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...] [options]

--image 		Image to be used for container creation
--env 		Set environment variables in the container
--port		Container port to be exposed 
--replicas	Number of containers in Pod
--dry-run		If true, only print the object that would be sent, without sending it.
--overrides	An inline JSON override for the generated object
--command		If true and extra arguments are present, use them as the 'command' field 		in the container.

Please Note – when you define replicas , Kubernetes creates a deployment and replica set to always maintain the desired set of pods running.

Create Pod using YAML file.
In  this example we are going to create Pod with name “ngnix-demo-yaml” , image “ngnix” will be used. Container will be exposed to port 80.

# cat ngnix-demo.yaml
---
apiVersion: v1
kind: Pod
metadata:
  name: ngnix-demo-yaml
  labels:
    app: ngnix-web
spec:
   containers:
     - name: ngnix-demo-yaml
       image: nginx
       ports:
     - containerPort: 80

Kick of the Pod Creation.
# kubectl create –f ngnix-demo.yaml

Following options can be configured in the YAML config file.
name           ports            readinessProbe            stdin
image          env              livecycle                 stdin
command        resources        terminationMessagePath    stdinOnce
args           volumeMounts     imagePullPolicy           tty
workingDir     livenessProbe    securityContext

Commonly used Pod Commands

List all Pods
# kubectl get pods
# kubectl get pods –o wide

Get details about the Pod
# kubectl describe pods NAME

Get Pod details in JSON format
# kubectl get pods -o json NAME

Delete a POD 
# kubectl delete pod NAME

If YAML file is present 
# kubectl delete   -f   YAML_FILE

Delete a pod immediately (no graceful shutdown)
# kubectl delete pod foo --now 

Delete all pods 
# kubectl delete pods --all

Great info-bites Yogesh Mehta - thanks for the many rapid information shares you put out here.

Like
Reply

To view or add a comment, sign in

Others also viewed

Explore content categories