Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 1.89 KB

K8-CreatingPod-Declerative.md

File metadata and controls

51 lines (34 loc) · 1.89 KB

LAB: K8s Creating Pod - Declarative Way (With Yaml File)

This scenario shows:

  • how to create basic K8s pod using yaml file,
  • how to get more information about pod (to solve troubleshooting),

Steps

  • Run minikube (in this scenario, K8s runs on WSL2- Ubuntu 20.04) ("minikube start")

    image

  • Create Yaml file (pod1.yaml) in your directory and copy the below definition into the file:

apiVersion: v1      
kind: Pod                         # type of K8s object: Pod
metadata:
  name: firstpod                  # name of pod
  labels:
    app: frontend                 # label pod with "app:frontend"   
spec:
  containers: 
  - name: nginx                   
    image: nginx:latest           # image name:image version, nginx downloads from DockerHub
    ports:
    - containerPort: 80           # open ports in the container
    env:                          # environment variables
      - name: USER
        value: "username"

image

  • Apply/run the file to create pod in declerative way ("kubectl apply -f pod1.yaml"):

    image

  • Describe firstpod ("kubectl describe pods firstpod"):

    image

  • Delete pod and get all pods in the default namepace ("kubectl delete -f pod1.yaml"):

    image

  • If you want to delete minikube ("minikube delete"):

    image