Kubernetes Fundamental – Part 6

In Part 1, We have gone through what is Kubernetes and its architecture.

In Part 2, We have gone through the key components such as NodesNamespaces and Pods.

In Part 3, we have gone through the components such as  ServiceJob and Ingress.

In Part 4, we have gone through the components such as   ConfigMap , Secret ,Volume , Deployment and StatefulSet .

In Part 5, we have gone through the definition and configuration of Kubernetes resources.

In this part, let us delve in to how we can setup and Kubernetes cluster locally using Minikube and kubectl.

Install minikube AND KUBECTL

  • First, we need to ensure that Hypervisor ( VirtualBox, Hyper-V or KVM) is installed on the machine as it is required by Minikube to run the virtual machine.
  • Install minikube : Download and install the Minikube by following the instruction from this link .
  • Ensure the Minikube is installed by running the following command in your terminal.
minikube version

It should display installed version of minikube.

  • Install kubectl: Download and install the kubectl using this link which is a client tool to interact with Kubernetes Cluster.
  • Verify the installation using the following command and it returns the installed version.
kubectl --version

Start minikube cluster

  • Start the Kubernetes cluster locally using the following command.
minikube start

Minikube will start a Virtual Machine and setup Kubernetes Cluster inside it.

  • Once the cluster is up and running, we can verify using the following.
kubectl cluster-info

This will show the URL for accessing the Kubernetes Cluster.

  • Verify the Kubernetes nodes.
kubectl get nodes

We could see the single node (a minikube virtual machine) listed as ready .

DEPLOY A TEST application

  • To make sure, the setup is configured correct and let us verify by deploying a sample application. Let us create a simple YAML file as below.
apiVersion: v1
kind: Pod
metadata:
name: test-app-pod
spec:
containers:
- name: test-app-container
image: nginx:latest
ports:
- containerPort: 80
  • Apply the configuration to create a test pod
kubectl apply -f test-app.yaml
  • Check the status of the pod
kubectl get pods

It will shows the current status of the pod is running .

  • Access the test application
kubectl port-forward test-app-pod 8080:80

We can test the application by running the URL : http://localhost:8080 on the web browser. Now we can see the default Nginx page.

commonly used commands

We can interact with Kubernetes Cluster using kubectl commands to inspect and manage your application pods and other resources in the cluster .

  • To check the status of the cluster and its component
kubectl cluster-info
  • To get the list of resources (pods, services and deployment) in our namespace.
kubectl get <resource>

resource : Either Pod or service or deployment resource

  • To get detailed information about specific resource
kubectl describe <resource> <resource_name>

resource : Pod or service or deployment

resource_name : Name of the specific resource instance.

  • To create or apply a Kubernetes resource from a YAML configuration file.
kubectl apply -f <filename>

filename – Name of the YAML configuration file to create /upgrade the resource.

  • To delete a resource
kubectl delete <resource> <resource_name>

resource : Pod or service or deployment

resource_name : Name of the specific resource instance.

  • To view the pods in our namespace
kubectl get pods
  • To view the logs inside the pod
kubectl logs <pod_name>

pod_name : Pod of the name

  • To access the interactive shell inside the pod
kubectl exec -it <pod_name> - /bin/bash

pod_name : Pod of the name

  • To view the services in our namespace
kubectl get services
  • To access a service from our local machine
kubectl port-forward <service_name> <local_port>:<service_port>

service_name : Name of the service.

local_port : Port on our local machine.

service_port: Port on our service we want to access.

  • To scale the pods of the deployment
kubectl scale --replicas=2 deployment/<deployment_name>

deployment_name : Name of the deployment

It will scale up the deployment by running two instances of the application.

These are the basic kubectl commands that allow you to interact with your Kubernetes cluster. In the next post, we will explore additional advanced commands to manage and monitor our application effectively.

Happy Container’ising 🙂