K8-CreatingPod-Declerative.md
March 23, 2023 ยท View on GitHub
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")

-
Create Yaml file (pod1.yaml) in your directory and copy the below definition into the file:
-
File: https://github.com/omerbsezer/Fast-Kubernetes/blob/main/labs/pod/pod1.yaml
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"

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

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

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

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