It all started yesterday, I was playing with azure services and reading through their documentation, and literally out of nowhere, my friend told me about Linode on a phone call. I thought it might be worth giving a shot on this cloud platform (and it was 😉).
I went ahead and created an account on Linode, and saw their various offerings but one service caught my eye and that was Kubernetes. I realized how much effort it took for me to set up the k8s cluster on my local Linux VM on Vmware. Believe me, Setting up your own Kubernetes cluster can be a little bit of extra work depending on which platform you use (it is a bit of work if you plan to do it on a local VM). It is very easy to set up a cluster on cloud platforms.
Today in this tutorial we will talk about Linode.
THIS TUTORIAL IS NOT FOR LINODE PROMOTION.
- It is cheaper than other big bois (AWS, Azure).
- It is very easy.
- Beginner friendly if you want to see k8s in action.
- Create a Linode account from here.
- Basic knowledge about k8s.
- A Linux machine (you can use WSL).
What will you learn?
- Create worker nodes on Linode.
- Make your local Linux machine the master node.
- Deploy a sample nginx image on all nodes.
- Use the Nodeport service to access port 80.
- Watch your deployment.
Let’s Start….(shall we?)
Step 1: Open your Linode dashboard, find Kubernetes service, and click on create a cluster.
Step 2: Enter the details and select the shared CPU, and add the minimal plan to save some money 😅.
Click on Create Cluster.
Step 3: Wait for your 3 worker nodes to get up and running.
You see, We only have worker nodes here. You might ask where is the master node and yeah that’s right. But no worries Linode will come to the rescue by providing us with a FREE Master node.
That master node will be our local Linux machine. I will be using WSL for this tutorial but you can use whatever you want.
Step 4: Click on view beside your kube_cluster_config.yaml & yes you can download this file right away to avoid extra work. If you did this then skip to step 7.
Step 5: Copy the contents of the yaml file.
Step 6: Open your local Linux machine & create a yaml file and copy this code into it.
Step 7: Time to install kubectl on your local machine by this command.
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
Step 8: Make this downloaded kubectl an executable.
sudo chmod 700 kubectl
Step 9: Move this command to your path so you can access it from anywhere.
sudo mv ./kubectl /usr/local/bin/kubectl
Step 10: Remember step 6? now you need to give the path of your config.yaml to set an environment variable. Add this line to your terminal ./bashrc if you using bash or ./zshrc
After this step, your local machine will act as Master Node.
Step 11: Type the following command to see if your worker nodes are successfully connected to your master node.
kubectl get nodes
It’s time for us to deploy some images on it.
Step 12: Create a new file named deployment.yaml and add the following code to it.
- name: static-site
- containerPort: 80
Step 13: Create a deployment.sh, file to automate the process of deployment and node port. Add the following code to it.
kubectl apply -f deployment.yaml
echo "\nGetting more info on deployment.yaml"
kubectl describe deployment demopods-deployment
echo "\nListing the number of pods created by this deployment.\n"
kubectl get pods -o wide
echo "\nExposing deployment.\n"
kubectl expose deployment demopods-deployment --type=NodePort --name=expose-service
echo "\nGetting Services"
kubectl get svc
Now either give execute permission to this file or simply type “sh deployment. sh” on the terminal to execute this file. It will deploy an nginx image and expose port number 80.
Your output should look like this.
Step 14: Note down the Port number beside the 80, In my case that is 32563.
Type the following command to check if your pods are up and running.
kubectl get pods
Step 15: Login into one of your worker nodes and type ifconfig in the terminal.
Step 16: Note down the eth0 IP address. In my case, it is 220.127.116.11
Step 17: Type the following command along with the IP address from step 16 and the port number from step 14 to if your deployment is working successfully.
Step 17: You can also type that IP address and port number in your browser & you will see the nginx page is working.
Well… we successfully created a Kubernetes cluster and deployed a sample nginx image on it. We will talk about AKS clusters next time 😉