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.

Tutorial 2 of 5 5 resources in this section

Section overview

5 resources

Covers 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

  1. Exercise 1: Create a Deployment for an Nginx server using the Docker image nginx:1.17.10 and name it nginx-deployment.

Solution: kubectl create deployment nginx-deployment --image=nginx:1.17.10

  1. Exercise 2: Create a LoadBalancer Service for the nginx-deployment on port 80.

Solution: kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80

  1. Exercise 3: Scale the nginx-deployment to 3 replicas.

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.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Word to PDF Converter

Easily convert Word documents to PDFs.

Use tool

AES Encryption/Decryption

Encrypt and decrypt text using AES encryption.

Use tool

Image Converter

Convert between different image formats.

Use tool

Random Password Generator

Create secure, complex passwords with custom length and character options.

Use tool

WHOIS Lookup Tool

Get domain and IP details with WHOIS lookup.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI 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 article

AI 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 article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help