Play-with-K8s

Play with Kubernetes is a free online tool which allows us to create K8 environments for testing purposes. You will need to have either a Github or a Docker account in order to gain access. Note that, each session is only valid for maximum of 4 hours. This tool will also allow us to create clusters that consist of master nodes and slave nodes. In addition to that we can also deploy apps on it using simple commands.


To access Play-with-K8s, go to https://labs.play-with-k8s.com/ and login with Github or a Docker account.



Creating the cluster


In this example we'll be creating 1 master node and 3 worker nodes. Go through the steps below to create this cluster environment.


Step 1

Creating the 4 instances for the nodes.


Step 2

Initiating the master node by running the following command in node1 instance terminal.

kubeadm init --apiserver-advertise-address $(hostname -i)


Once this is done node1 should look like below.


Also notice, once the above command is run successfully, it'll output a few other commands as a result and we must note them down and run in next steps (Step 3 & 5) in order to enable kubectl as well as to join the worker nodes to the master node.


Step 3

Enabling kubectl on a master node (execute on node1).

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config


Step 4

Initialize the cluster network (execute on node1). This command was given to us in Step 1, when creating the instances.

kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml


Step 5

Joining the worker nodes (execute on node2, node3 & node4).

kubeadm join 192.168.0.13:6443 --token 61ndr8.1l1zmrm2ph8g1qc9 \ --discovery-token-ca-cert-hash sha256:f631908eb5acbb6b3d21a1b95d07f8726fd44c6ae003050b60a11a9a76f84fda


Now our cluster should look like below with all the worker nodes connected to the master.




Testing the environment


We should now be able to test our environment by running the kubectl commands in node1 as below.


Get all nodes

kubectl get nodes




Deploying a sample app


Additionally, we can deploy a sample Nginx app on the worker nodes by running the command in node1 below.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/nginx-app.yaml


The check for PODs as below

kubectl get pods -o wide



As shown, Nginx app has been deployed on all 3 worker nodes.


Category: Software Dev

Published: Mar 17 2022

Categories