Create a Deployment on Kubernetes

mabis12

Abisola Adesegun

Posted on September 26, 2024

Create a Deployment on Kubernetes

Table of Contents
Step 1: Install Prerequisites
Step 2: Start Minikube
Step 3: Create an Nginx Deployment
Step 4: Expose the Deployment (Optional)
Step 5: View the Deployment in a Browser
Step 6: Access the Kubernetes Dashboard

Kubernetes also known as K8s, is an open source system for automating deployment, scaling, and management of containerized applications. Modern applications are increasingly built using containers, which are microservices packaged with their dependencies and configurations.

Kubernetes (pronounced “koo-ber-net-ees”) is open-source software for deploying and managing those containers at scale—and it’s also the Greek word for helmsmen of a ship or pilot. Build, deliver, and scale containerized apps faster with Kubernetes.
Here’s a step-by-step guide to create an Nginx deployment on Kubernetes using Minikube and Kubectl, and view it in your browser.

Step 1: Install Prerequisites
Install Docker Desktop:

Download the latest release of Docker Desktop from the official site.
Install Minikube:
Download the Minikube installer from the Minikube releases page.

Step 2: Start Minikube
Open a command prompt or PowerShell as an administrator.
To start Minikube:

Copy code
minikube start
This command starts a local Kubernetes cluster using Docker.

Image description

Step 3: Create an Nginx Deployment
Create a deployment using Kubectl

kubectl create deployment nginx --image=nginx

Image description

Verify the Deployment

  • You can check the status of your deployment by running below code.

kubectl get deployments

Image description

  • To view the running pods:

Copy code
kubectl get pods

Image description

You should see 3 pods for the NGINX deployment.

Step 4: Expose the Deployment (Optional)
If you want to expose your deployment via a service (e.g., to access it from outside the cluster), you can use the following command to create a service of type LoadBalancer or NodePort:

Copy code
kubectl expose deployment nginx --type=NodePort --port=80

Image description

  • To view all services:

Copy code
kubectl get service

Image description

This will expose the deployment and allow traffic to reach your NGINX pods.

Step 5: View the Deployment in a Browser

  • Get the URL for the service:

Copy code
minikube service nginx --url

Image description

  • Open the provided URL in your web browser to see the Nginx welcome page.

Image description

Step 6: Access the Kubernetes Dashboard

  • Start the Kubernetes dashboard:

Copy code
minikube dashboard
This command will open the Kubernetes dashboard in your default web browser, where you can explore your cluster and manage resources.

Image description

Image description

View pod

Image description

I just successfully set up a local Kubernetes cluster, deployed an Nginx application, and viewed it in my browser.

💖 💪 🙅 🚩
mabis12
Abisola Adesegun

Posted on September 26, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Create a Deployment on Kubernetes
docker Create a Deployment on Kubernetes

September 26, 2024