(K8s) Kubernetes lab 103 Pods with Yaml
Step 0 : Create docker hub account. https://hub.docker.com
Step 1 : Open Play with Kubernetes login with your docker hub account.
Step 2 : Click on start
Step 3 : It will start a 4 hr session, click on + ADD NEW INSTANCE
Step 4 : Click in terminal and run steps from lab 101 to build cluster
Please check k8slab 101 https://www.shrlrn.com/practice/k8slab-101
create three instance
on first instance enter below command
kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16
capture output of kubeadm join XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
enter captured command in second and third node
enter below command on first node
kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml
Step 5 : vi pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: demo
labels:
app: demo
type: web
spec:
containers:
- name: demo-nginx
image: nginx
ports:
- containerPort: 80
create a new file pod.yaml
apiVersion, Kind, metadata.name and spec are required field
you may add labels
you can use any key: value pairs for labels
labels are used to select pods
provide name to container
provide image for container
Step 6 : kubectl apply -f pod.yaml
this command will create pod
Step 7 : kubectl get pods
this command will list all the pods in default namespace
Step 8 : kubectl exec -it demo -- bash
this command will provide prompt inside pod
run ls -la to check files inside pod
Step 9 : kubectl logs demo
this command show logs for app running in pod
Step 10 : kubectl logs -f demo
this command will print pod logs on terminal
it will follow logs
use Ctl + c t stop logs and exit
Step 11 : kubectl logs -f demo --tail=1
tail command will start from current logs
with 1 recent log
Step 12 : kubectl get pods -o wide
this command will list all pods with information of node pods are running
Step 13 : kubectl describe pod demo
this command will provide details of pod
Step 14 : kubectl get pods demo -o yaml
this command will provide details similar to describe but in yaml format
Step 15 : kubectl get pods demo -o json
this command will provide details similar to above commands in json format
Step 16 : kubectl delete pod demo
this command will delete pods demo