Kubernetes gives system administrators the means to manage containerized applications. To get started, we need to deploy an application inside of our Kubernetes cluster. From there, Kubernetes will manage many aspects of our application, plus give us tools to interact with it as needed. In this tutorial, we will go through the step by step instructions to deploy an application in Kubernetes on a Linux system.
In this tutorial you will learn:
- How to build a Docker image
- How to deploy a Docker image to Kubernetes
- How to check status info on deployed applications
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Deploy an Application in Kubernetes step by step instructions
The instructions assume that you already have your Kubernetes cluster up and running. In the steps below, we will be creating a containerized application by using Docker, and then deploying that application on to our Kubernetes cluster. Let’s get started!
Create Docker Image
The first thing we will do is create a Docker image using Dockerfile. This will just be a simple image that contains a default Apache web server for our example, but feel free to build an image of whatever application you need to. Our
Dockerfilecontains the following:
FROM ubuntu:22.04 LABEL maintainer="email@example.com" RUN apt-get update && apt-get -y install apache2 EXPOSE 80
Move into the root directory of your project and run the
docker buildcommand to build your image.
$ sudo docker build -t linuxconfig/apache .
- We can verify that the Docker image was created and is ready to use by executing:
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE linuxconfig/apache latest 4c7c99b254a2 22 seconds ago 228MB
- You can now upload your application to a central repository such as Docker Hub for global access.
$ docker login $ docker push linuxconfig/apache
- Next, let’s create a Kubernetes deployment manifest file. There are many options we can apply in this file, including the amount of replicas that we want to run. Since this is our first time deploying an application in Kubernetes, we will keep it simple in this example, and not include any replicas or scaling. Create the following file and substitute any values accordingly:
apiVersion: v1 kind: Pod metadata: name: apache spec: containers: - name: apache2 image: linuxconfig/apache:latest ports: - containerPort: 6379
We will save this file as
- Next, deploy the application on to Kubernetes using the following
$ kubectl create -f apache-deployment.yml
Note: you may need to run the command with
sudo, depending on your Kubernetes configuration.
- To see your pod deployment, as well as any others, execute the following command:
$ kubectl get pods
We can see additional information about the specific application we just deployed by executing:
$ kubectl get pods/apache
And more detailed information with the
$ kubectl describe pods/apache
In this tutorial, we saw how to deploy an application in Kubernetes on a Linux system. We used Docker to create a simple image, upload it to a central repository, and then use the
kubectlcommand to retrieve the container and deploy it onto our Kubernetes cluster. Using the
kubectl describecommand, we can see the deployed container running on a worker node in our cluster.