DevOps / Kubernetes and Container Orchestration
Deploying Applications on Kubernetes
In this tutorial, we will walk you through the steps involved in deploying an application on Kubernetes. You will learn to create and manage Deployments and Services.
Section overview
5 resourcesCovers managing and orchestrating containerized applications using Kubernetes.
1. Introduction
In this tutorial, we will learn how to deploy an application on Kubernetes, a popular open-source platform for managing containerized workloads and services. We will create and manage Deployments and Services.
By the end of this tutorial, you will be able to:
- Understand the basics of Kubernetes
- Create a Deployment
- Deploy an application on Kubernetes
- Create a Service
Prerequisites
- Basic knowledge of Docker
- A local setup of Kubernetes (like Minikube) or an account on a cloud platform offering Kubernetes (like Google Cloud)
- kubectl command line tool installed. It is the Kubernetes command-line tool, which allows you to run commands against Kubernetes clusters.
2. Step-by-Step Guide
Kubernetes Deployments
A Deployment provides declarative updates for Pods and ReplicaSets. You describe the desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state.
Kubernetes Services
A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them - sometimes called a micro-service. It can be exposed in different ways by specifying a type in the ServiceSpec.
Deploying an Application
Step 1: Create a Deployment
Let's assume you have a Docker image of your application named my-app:v1. To create a Deployment for this:
kubectl create deployment my-app --image=my-app:v1
This command creates a Deployment named my-app using the Docker image my-app:v1.
Step 2: Check Deployment Status
kubectl get deployments
This command lists all the Deployments in the Kubernetes cluster.
Step 3: Create a Service
To expose your application to external traffic, you need to create a Service:
kubectl expose deployment my-app --type=LoadBalancer --port=8080
This command creates a Service named my-app which exposes the Deployment my-app on port 8080.
Step 4: Check Service Status
kubectl get services
This command lists all Services in your Kubernetes cluster.
3. Code Examples
Creating a Deployment
kubectl create deployment my-app --image=my-app:v1
In this command:
- kubectl create deployment: Command to create a new Deployment.
- my-app: Name of the Deployment.
- --image=my-app:v1: Docker image to use for the Deployment.
Creating a Service
kubectl expose deployment my-app --type=LoadBalancer --port=8080
In this command:
- kubectl expose deployment: Command to expose the Deployment as a Service.
- my-app: Name of the Deployment to expose.
- --type=LoadBalancer: Type of the Service. A LoadBalancer Service is a Service accessible externally via a cloud provider's load balancer.
- --port=8080: Port to expose the Service on.
4. Summary
In this tutorial, we learned how to create and manage Deployments and Services in Kubernetes. We have also learned how to deploy an application and expose it to external traffic.
For more learning, you can read the official Kubernetes documentation.
5. Practice Exercises
- Exercise 1: Create a Deployment for an Nginx server using the Docker image
nginx:1.17.10and name itnginx-deployment.
Solution: kubectl create deployment nginx-deployment --image=nginx:1.17.10
- Exercise 2: Create a LoadBalancer Service for the
nginx-deploymenton port80.
Solution: kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80
- Exercise 3: Scale the
nginx-deploymentto3replicas.
Solution: kubectl scale deployment/nginx-deployment --replicas=3
Remember to practice regularly and experiment with different commands and configurations to deepen your understanding of Kubernetes.
Need Help Implementing This?
We build custom systems, plugins, and scalable infrastructure.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Latest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI in Public Safety: Predictive Policing and Crime Prevention
In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…
Read articleAI in Mental Health: Assisting with Therapy and Diagnostics
In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…
Read articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article