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 web and image nginx
name: web
image: nginx
Use Kubectl command
verify with below command
kubectl get pods
this command will create pod with image nginx and name web
kubectl run web --image=nginx
Task: Delete pod you created in previous step using kubectl
verify with below command
kubectl get pods
kubectl delete pod web
this command will delete pod with name web
Task: Create a pod using Kubectl and expose port
name: web
image: nginx
port: 80
verify with below command
kubectl get all
kubectl run web --image=nginx --port=80
Task: Create a pod using Kubectl and expose port, port should be accessible from outside Kubernetes cluster
name: web
image: nginx
port: 80
verify with below command
kubectl get all
kubectl expose pod web --port 80 --name=nginx-svc --type=NodePort --target-port=80
Task: Find port used by nodeport service in Kubernetes to expose container
kubectl get all
Task: Access container port using browser
Task: Create nodeport service using kubectl command
name: nginx-svc
container port: 80
target port: 80
nodeport: 3001
verify with below command
kubectl get svc
kubectl create service nodeport nginx-svc1 --tcp=80:80 --node-port=30001
Task: Try accessing nodeport using URL with port 30001
It will not work as nodeport service require label to match container
Add label to get nodeport service working
verify with below command
kubectl describe svc nginx-svc1
kubectl label pod web app=nginx-svc1
Task: Access container port using browser
Task: Use kubectl command to generate yaml for creating a pod
name: web
image: nginx
kubectl run web --image=nginx --dry-run=client -o yaml
Task: Which node is pod running on?
kubectl get pods -o wide
Task: Delete pod you created in previous step using kubectl
verify with below command
kubectl get pods
kubectl delete pod web
this command will delete pod with name web
Task: Delete all open nodes/instances and close session