Unlocking the Power of Kubernetes: Part 4 of Day 01

Unlocking the Power of Kubernetes: Part 4 of Day 01

Welcome to Part 4 of Day 01 of the #5DaysOfKubernetes challenge! Today, we’ll dive into the practical aspect of working with Kubernetes. We’re going to set up Minikube, a tool that enables you to run a Kubernetes cluster on your local machine or an AWS instance.

Why Set Up Minikube?

Before we begin, you might be wondering why it’s essential to set up Minikube. Well, Minikube provides an excellent environment for learning and experimenting with Kubernetes without the need for a full-scale cluster. It’s perfect for developers and enthusiasts who want to get hands-on experience with Kubernetes in a controlled environment.

Prerequisites

To follow along with this tutorial, you’ll need the following:

  • An AWS account (if you’re setting up on an AWS instance).

  • Basic knowledge of AWS and Linux terminal commands.

Let’s get started!

Setting Up Minikube on AWS Instance

Here, I am creating an EC2 Instance to set up minikube on the server. If you are comfortable setting up minikube on your local then feel free to jump on the minikube setup.

Enter the name of the machine and select the Ubuntu22.04 AMI Image.

Make sure to select the t2.medium instance type as Master node 2CPU cores which is present in the t2.medium instance type.

Create a new key pair and select the Private key file format according to your OS(For Windows select .ppk or for Linux select .pem).

Open port 22 and rest you can leave it.

Now, go to your Downloads folder or where you have downloaded your pem file and change the permission by running the command ‘chmod 400 <Pem_file_name>

Now, connect your instance by copying the given command below.

As you can see I logged in to the Instance.

Now, run the following commands to install minikube on your local machine or AWS machine.

sudo apt update -y && sudo apt upgrade -y
sudo reboot

After 3 to 4 minutes, reconnect with the instance through ssh

sudo apt install docker.io
sudo usermod -aG docker $USER && newgrp docker
sudo apt install -y curl wget apt-transport-https
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube version

I have given the line break in the below curl command, kindly avoid the break and any whitespaces after `. You can refer to the below screenshot.

curl -LO https://storage.googleapis.com/kubernetes-release/release/`
curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

chmod +x kubectl
sudo mv kubectl /usr/local/bin
kubectl version -o yaml
minikube start - vm-driver=docker

Now, to verify the installation you can run the given command and if you get the result in the snippet then your installation is completed.

minikube status

You can also validate your kubectl version by running the command.

kubectl version

Now, run the given command after 4 to 5 minutes which will show the nodes.

kubectl get nodes

Creating Your First Pod

To get some hands-on experience, let’s create a simple manifest file and deploy a pod on your Minikube cluster. Don’t worry if you don’t understand everything in the manifest file; we’ll cover that in later days.

Create a new file and copy the given content to your file without editing anything. While running the manifest file, if you get any error then it must be related to the indentation of the file. So, check the file again.

vim Day04.yml
kind: Pod                              
apiVersion: v1                     
metadata:                           
  name: testpod                  
spec:                                    
  containers:                      
    - name: c00                     
      image: ubuntu              
      command: ["/bin/bash", "-c", "while true; do echo Hello-Kubernetes; sleep 5 ; done"]
    - name: container2
      image: ubuntu
      command: ["/bin/bash", "-c", "while true; do echo Second Container is still running; sleep 3 ; done"]
  restartPolicy: Never

Deploy the Pod:

Run the following command to deploy the pod:

kubectl apply -f Day04.yml

List Pods:

To list all the pods, use this command:

kubectl get pods

Check Logs:

You can check the logs of the primary container with:

kubectl logs -f pod1

To check the logs of the primary container, specify the container name:

kubectl logs -f pod1 -c container1

To check the logs of the second container, specify the container name:

kubectl logs -f pod1 -c container2

Delete the Pod:

To delete the pod, use this command:

kubectl delete pod pod1

To list the IP of the pod, use the below command.

kubectl pod pod1 -c container1 — hostname -i

To delete the pod by specifying the manifest file name

kubectl delete -f Day04.yml

Conclusion

Congratulations! You’ve successfully set up Minikube on your local machine or an AWS instance and created your first pod. In the coming days, we’ll dive deeper into Kubernetes concepts, so stay tuned.

Stay Tuned for More:

Don’t forget to hit that follow button to stay updated with each day’s Kubernetes insights and tutorials. We’re on a mission to make complex concepts easy to understand, so follow along and level up your skills.

Stay connected on LinkedIn: LinkedIn Profile

Stay up-to-date with GitHub: GitHub Profile

Feel free to reach out to me, if you have any other queries.

Happy learning, Kubernetes explorers! 🚢🌐