Followers

Kubernetes Pod commands and manifest file

To Create the pod ( with name nginx-pod by using nginx docker image)  with command      kubectl run nginx-pod --image nginx To list the pod ...


To Create the pod ( with name nginx-pod by using nginx docker image)  with command

    kubectl run nginx-pod --image nginx

To list the pod with its IP address and NodeName

    kubectl get pods -o wide

To interact with pod's terminal(go inside the pod)

    kubectl exec -it nginx-pod-- bash

To Exit from the pod run "exit" command

To access the application running in the pod ( consider 192.168.135.2 is IP of the pod)

     curl 192.168.135.2

To find all the properties of the pod in yaml format

    kubectl get pods nginx-pod -o yaml

To find all the properties of the pod in json format

    kubectl get pods nginx-pod-o json

To Delete the Pod

    kubectl delete pod nginx-pod

Manifest file in Kubernetes 

IDE (Integrated Development Environment)

    Visual Studio Code (VS Code Download)

    Notepad/Notepad++

    Sublime text editor

    Atom

Kubernetes Documentation

My First Pod Manifest file (nginx-pod.yaml)

apiVersion: v1 # apiVersion for the resource
kind: Pod  # type of resource (Pod)
metadata:
  name: myapp # Pod name
  labels:  # user defined key value pair
    name: myapp # name is the key and myapp is value
spec:
  containers: # Containers information for the pod
  - name: myapp # name of the container to access via pod
    image: nginx # docker image for myapp container
    # below code is optional
    resources: # resources define the memory or cpu limits for a container
      limits:  # maximum limit for the container
        memory: "128Mi"  # maximum 128 mb of memory used by the container
        cpu: "500m"  # maximum cpu usage 500mz
    ports: # Ports where the container's app is running
      - containerPort: 80 # nginx runs on port 80

To create Pod by using above file you need to run below command

            kubectl create -f nginx-pod.yaml

To Verify Pod is created with its IP address and other properties

             kubectl get pods -o wide

To Verify the events and other run-time properties of the pod.

          kubectl describe pod myapp

If you make any change in the manifest file then use the  apply(change/create) command

          kubectl apply -f nginx-pod.yaml

To find the logs generated by pod

         kubectl logs myapp

To interact with pod

         kubectl exec -it myapp -- bash

To delete the pod using manifest file

          kubectl delete -f nginx-pod.yaml

To verify pod is deleted or not

        kubectl get pods


MultiContainer Pod

Create 2 containers (nginx, tomcat) within a single pod multicont.yaml

apiVersion: v1
kind: Pod
metadata:
  name: myapp
  labels:  
    name: myapp
spec:
  containers:
  - name: nginx-container
    image: nginx
     # below code is optional
    resources:
      limits:  
        memory: "64Mi"  
        cpu: "100m"  
    ports:
      - containerPort: 80 # nginx runs on port 80
  - name: tomcat-container
    image: tomcat  
    # below code is optional
    resources:
      limits:  
        memory: "64Mi"  
        cpu: "200m"  
    ports:
      - containerPort: 8080 # tomcat runs on port 8080

To create Pod by using above file you need to run below command

            kubectl create -f multicont.yaml

To Verify Pod is created with its IP address and other properties

             kubectl get pods -o wide

To Verify the events and other run-time properties of the pod.

          kubectl describe pod myapp

If you make any change in the manifest file then use the  apply(change/create) command

          kubectl apply -f multicont.yaml

To find the logs generated by pod nginx-container

        kubectl logs myapp -c nginx-container

To find the logs generated by pod nginx-container

        kubectl logs myapp -c tomcat-container

To interact with pod for nginx-container

    kubectl exec -it myapp -c nginx-container -- bash

To interact with pod for tomcat-container

    kubectl exec -it myapp -c tomcat-container -- bash

To access nginx app using multicontainer pod (IP 192.168.135.3)

    curl 192.168.135.3:80

To access tomcat app using multicontainer pod (IP 192.168.135.3)

    curl 192.168.135.3:8080

To delete the pod using manifest file

          kubectl delete -f multicont.yaml

To verify pod is deleted or not

        kubectl get pods

COMMENTS

BLOGGER: 1
  1. Hi Raman, try to change the pod image at runtime from nginx to ubuntu the pod1 get crashed and status showing is "CrashLoopBackoff"
    events which run are have message as "Back-off restarting failed container "

    ReplyDelete

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: Kubernetes Pod commands and manifest file
Kubernetes Pod commands and manifest file
DevOpsWorld
https://www.devopsworld.co.in/2022/02/kubernetes-pod-commands-and-manifest.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2022/02/kubernetes-pod-commands-and-manifest.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content