K8S - exercise 1: create, fix, get, and delete PODS
Sebastian
Posted on February 4, 2024
This exercise is based on the course LinuxFoundationX LFS158x
Introduction to Kubernetes.
Create a pod in a declarative way
create a file called pod.yaml
touch pod.yaml
vim pod.yaml
past this code in pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Run the command:
kubectl create -f pod.yaml
Create a pod in a imperative way
kubectl run firstrun --image=nginx
Get pods to see the new pod:
kubectl get pods
kubectl get pods -o wide
Create a pod in a mix way (declarative and imperative)
kubectl run firstrun --image=ngixx --port=88 --dry-run -o yaml > secondrun.yaml
If you notice, I introduced some errors in the YAML file so that I can fix them.
Modify because it is not possible to have two pods with the same name and label:
name, label, container -> name
kubectl describe secondrun
Run this command, to replace the previous pod:
kubectl replace --force -f secondrun.yaml
Now let's delete the pods:
kubectl delete -f pod.yaml
kubectl delete pods firstrun secondrun
💖 💪 🙅 🚩
Sebastian
Posted on February 4, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
aws Mastering AWS Microservices Architecture for High-Traffic Systems: Interview Preparation
November 29, 2024
devops Mastering Packaging and devlopment: Packaging and Running Apps on Gunicorn.
November 29, 2024