Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Kubernetes Deployment Setup & Launch | CI/CD & Automation
Introduction to DevOps

bookKubernetes Deployment Setup & Launch

Now that your application runs smoothly inside containers, the next challenge is orchestrating and managing those containers at scale. This is where Kubernetes comes in to help.

To get started, you'll define your application's desired state using YAML files. One file will describe a Deployment, which handles updates and scaling, while another will define a Service, which exposes your application to the network and makes it accessible to users.

Note
Study More

YAML (YAML Ain't Markup Language) is a human-readable format for configuration files. It's often used to describe infrastructure, automate processes, and store application settings.

A Deployment ensures that the desired number of application instances (Pods) are always running and makes it easy to roll out updates or roll back to previous versions. A Service exposes these containers to the network and distributes incoming traffic between them.

Running Minikube

Note
Definition

Minikube is a lightweight tool that lets you run a local Kubernetes cluster on your computer. It creates a virtual environment where you can test and explore Kubernetes without needing any cloud services.

After installing Minikube and adding it to your system PATH, open PowerShell (or your terminal of choice) and run:

This command checks whether Minikube is available and displays the installed version.

Once you’ve confirmed Minikube is installed, start your local Kubernetes cluster with:

This command creates and launches a local Kubernetes cluster on your machine. It downloads necessary components and starts the control plane and worker nodes.

Deployment: Application Rollout

Start by creating the deployment.yaml file. A Deployment in Kubernetes ensures that a specific number of Pods (application instances) are always running and can be updated or rolled back without downtime.

deployment.yaml

deployment.yaml

copy

In this manifest, the replicas parameter specifies how many Pod instances should run at the same time β€” in this case, two. To know which Pods to manage, the Deployment uses a combination of selector and labels: the selector acts as a filter to find Pods with a specific label, and the Pod template defines that label. When the labels match, the Deployment treats those Pods as its own and takes care of maintaining their count, updating them, and restarting them if needed.

All Pods run on port 3000. They can all use the same port because each Pod operates in its own isolated network space, so there's no conflict between them.

Service: Network Access to the Application

Once the Deployment is in place, a Service is needed to provide network access and load balancing between Pods. Create the service.yaml file:

service.yaml

service.yaml

copy

This manifest defines a Service named my-app-service that directs traffic to Pods with the label app: my-app. It listens on port 80 externally and forwards requests to port 3000 inside the Pods.

The LoadBalancer type is important because it exposes the application externally and distributes traffic across Pods.

Deploying the Application in Kubernetes

Once the YAML files are ready, they can be applied to the cluster:

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

The kubectl apply -f command creates or updates resources in the cluster based on the YAML file contents.

Checking the Status

After applying the configuration files, it's important to confirm that everything has been deployed as expected. Since Pods and Services take a moment to start, begin by listing the running Pods:

If the deployment.yaml file specifies replicas: 2, two Pods should appear in the output.

To confirm that the Service is running and accessible:

This will display the Service’s IP address and the ports through which the application can be accessed.

Get the Service URL

To access your application, run the following command in PowerShell or your terminal:

This command asks Minikube to return the URL where your application is exposed. Minikube checks the Service you created (my-app-service) and provides a link you can open in your browser.

Scaling the Application

Kubernetes makes it easy to adjust the number of running Pods without stopping the application.

For example, to scale from 2 to 4 replicas:

Running kubectl get pods again will now list four active Pods.

Kubernetes provides powerful tools for managing containerized applications at any scale. A Deployment ensures the correct number of Pods are running and can be updated or rolled back easily. A Service exposes the application to the network and balances incoming traffic. YAML configuration files make setup clear and readable, while kubectl commands allow these configurations to be applied and managed in real time.

1. What is the main purpose of a Deployment in Kubernetes?

2. Why can multiple Pods run on the same port number (e.g., 3000) without conflicts?

question mark

What is the main purpose of a Deployment in Kubernetes?

Select the correct answer

question mark

Why can multiple Pods run on the same port number (e.g., 3000) without conflicts?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 9

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 3.7

bookKubernetes Deployment Setup & Launch

Swipe to show menu

Now that your application runs smoothly inside containers, the next challenge is orchestrating and managing those containers at scale. This is where Kubernetes comes in to help.

To get started, you'll define your application's desired state using YAML files. One file will describe a Deployment, which handles updates and scaling, while another will define a Service, which exposes your application to the network and makes it accessible to users.

Note
Study More

YAML (YAML Ain't Markup Language) is a human-readable format for configuration files. It's often used to describe infrastructure, automate processes, and store application settings.

A Deployment ensures that the desired number of application instances (Pods) are always running and makes it easy to roll out updates or roll back to previous versions. A Service exposes these containers to the network and distributes incoming traffic between them.

Running Minikube

Note
Definition

Minikube is a lightweight tool that lets you run a local Kubernetes cluster on your computer. It creates a virtual environment where you can test and explore Kubernetes without needing any cloud services.

After installing Minikube and adding it to your system PATH, open PowerShell (or your terminal of choice) and run:

This command checks whether Minikube is available and displays the installed version.

Once you’ve confirmed Minikube is installed, start your local Kubernetes cluster with:

This command creates and launches a local Kubernetes cluster on your machine. It downloads necessary components and starts the control plane and worker nodes.

Deployment: Application Rollout

Start by creating the deployment.yaml file. A Deployment in Kubernetes ensures that a specific number of Pods (application instances) are always running and can be updated or rolled back without downtime.

deployment.yaml

deployment.yaml

copy

In this manifest, the replicas parameter specifies how many Pod instances should run at the same time β€” in this case, two. To know which Pods to manage, the Deployment uses a combination of selector and labels: the selector acts as a filter to find Pods with a specific label, and the Pod template defines that label. When the labels match, the Deployment treats those Pods as its own and takes care of maintaining their count, updating them, and restarting them if needed.

All Pods run on port 3000. They can all use the same port because each Pod operates in its own isolated network space, so there's no conflict between them.

Service: Network Access to the Application

Once the Deployment is in place, a Service is needed to provide network access and load balancing between Pods. Create the service.yaml file:

service.yaml

service.yaml

copy

This manifest defines a Service named my-app-service that directs traffic to Pods with the label app: my-app. It listens on port 80 externally and forwards requests to port 3000 inside the Pods.

The LoadBalancer type is important because it exposes the application externally and distributes traffic across Pods.

Deploying the Application in Kubernetes

Once the YAML files are ready, they can be applied to the cluster:

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

The kubectl apply -f command creates or updates resources in the cluster based on the YAML file contents.

Checking the Status

After applying the configuration files, it's important to confirm that everything has been deployed as expected. Since Pods and Services take a moment to start, begin by listing the running Pods:

If the deployment.yaml file specifies replicas: 2, two Pods should appear in the output.

To confirm that the Service is running and accessible:

This will display the Service’s IP address and the ports through which the application can be accessed.

Get the Service URL

To access your application, run the following command in PowerShell or your terminal:

This command asks Minikube to return the URL where your application is exposed. Minikube checks the Service you created (my-app-service) and provides a link you can open in your browser.

Scaling the Application

Kubernetes makes it easy to adjust the number of running Pods without stopping the application.

For example, to scale from 2 to 4 replicas:

Running kubectl get pods again will now list four active Pods.

Kubernetes provides powerful tools for managing containerized applications at any scale. A Deployment ensures the correct number of Pods are running and can be updated or rolled back easily. A Service exposes the application to the network and balances incoming traffic. YAML configuration files make setup clear and readable, while kubectl commands allow these configurations to be applied and managed in real time.

1. What is the main purpose of a Deployment in Kubernetes?

2. Why can multiple Pods run on the same port number (e.g., 3000) without conflicts?

question mark

What is the main purpose of a Deployment in Kubernetes?

Select the correct answer

question mark

Why can multiple Pods run on the same port number (e.g., 3000) without conflicts?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 9
some-alt