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
Top comments (0)