Deploying our first app in the K8s pod

Deploying our first app in the K8s pod

In this blog, we will explore more deeply about Kubernetes. In the previous blogs, we discussed the Kubernetes architecture and management tools like kOps as the fundamentals of Kubernetes. In this blog, we will know about the Pod and deploy our application in the pod.

What is Pod?

A pod is similar to the container but the container is created using the Docker CLI commands while a Pod is created by writing the manifest in the YAML file. Therefore, to create a pod we should know YAML.

In a single pod, single or multiple containers can be created. By the way, in Kubernetes, everything is dealt with YAML file whether it is about creating pods, service, deployment, etc.

If we create multiple containers inside the pod, then Kubernetes provides shared networking and shared storage. In this way, the containers inside the pod can communicate with each other using the local host.

Setup

Kubectl - command line tool

Minikube - local development environment, single node architecture

  • To install Kubectl
sudo apt install kubectl -y
  • TO install minikube
sudo apt-get install -y minikube
  • To start minikube
minikube start

Our minikube is running and lets run some commands

  • To get node information
kubectl get nodes
  • To get Pods information
kubectl get pods

  • Let's write our first pod.yml file
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Here, this YAML code describes a Kubernetes Pod named "nginx" that runs a single container using the NGINX image version 1.14.2. The container exposes port 80, allowing traffic to access the NGINX web server within the Pod. This Pod definition is a basic configuration used for deploying a simple NGINX web server in a Kubernetes cluster.

  • To run the pod
kubectl apply -f pod.yml

Our pod is created successfully.

  • To get more details about the pod
kubectl get po pod_name -o wide

  • To enter into the container
minikube ssh

We do not need to enter the IP address to log into the container.

We can see our first ever Kubernetes application is created and is running perfectly.

  • To inspect the pod
kubectl describe pods pod-name

  • To get logs of the pod for any issue
kubectl logs pod_name

In this way, we can debug and view the logs of the Kubernetes pods. Pods are simple and easy to use. To enhance with features like autoscaling, and auto-healing, we will use the services and deployments in the upcoming blogs.

Happy Learning!!