In case you prefer a video, check below our YouTube video for this lab
Task: Create Kubernetes cluster with 3 worker nodes.
Master: 1 node
Worker: 2 node
Create docker hub account. Docker Hub if you already have one skip this step
Open Play with Kubernetes login with your docker hub account.
Click on start
It will start a 4 hr session
create three instance
click on + ADD NEW INSTANCE three time to add three instances
kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16
enter below command on first node
kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml
capture output of kubeadm join XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
enter captured command in second and third node
kubeadm join XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Task: Create a pod with name demo and image nginx
name: demo
image: nginx
Use Kubectl command
verify with below command
kubectl get pods
create a new file pod.yaml
vi pod.yaml
Press i to get in insert mode
apiVersion: v1
kind: Pod
metadata:
name: demo
labels:
app: demo
type: web
spec:
containers:
- name: demo-nginx
image: nginx
ports:
- containerPort: 80
use escape to exit insert mode and :wq to save and exit vi
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
kubectl apply -f pod.yaml
this command will create pod using yaml file
Task: Connect to pod and run ls -la to check directory structure
kubectl exec -it demo -- bash
this command will provide prompt inside pod
run ls -la to check files inside pod
Task: Check pod logs using kubectl command
kubectl logs demo
this command show logs for pod and app running in pod
Task: Use kubectl command to stream logs from pod and app inside pod
kubectl logs -f demo
this command will print pod logs on terminal
it will follow logs
use Ctl + c t stop logs and exit
Task: Use kubectl command to stream new logs from pod and app inside pod
get only 1 logs from history
kubectl logs -f demo --tail=1
tail command will start streaming from current logs
with 1 recent log
Task: Which node is pod running on?
kubectl get pods -o wide
Task: Find details on pods created in this lab
kubectl describe pod demo
this command will provide details of pod
Task: Use kubectl command to generate yaml for creating a pod
name: demo
image: nginx
kubectl run demo --image=nginx --dry-run=client -o yaml
Task: Use kubectl command to get pod details in json format
name: demo
image: nginx
kubectl run demo --image=nginx --dry-run=client -o json
Task: Delete pod you created in previous step using kubectl
verify with below command
kubectl get pods
kubectl delete pod demo
this command will delete pod with name web
Task: Delete all open nodes/instances and close session