Get startedGet started for free

Deploying a First (Stateless) Application

1. Deploying a First (Stateless) Application

Welcome back. Now, we will learn how to deploy stateless applications using Kubernetes. Before doing so, we will learn more about "kubectl" and Manifests.

2. More on "kubectl"

As we already know, "kubectl" is the main tool for interacting with Kubernetes. Here are th important kubectl commands we will use: We can create and change objects such as pods or services in Kubernetes using "create" and "apply", using the command line option "-f" which is short for "file" We can see a summary of objects by using the "get" command, detailed information is available with the command "describe". "kubectl" is also a great tool for monitoring the state of Kubernetes. It comes with extensive help, which is available via the command line switch "--help"

3. More on Manifests

Manifests are declarations that come in YAML or JSON format. On the left-hand side, we see an example of a YAML Manifest. There are two important sections: "metadata" with essential meta-information, and "spec" to declare object specifications. These sections can be quite deep, depending on what is being declared. The Manifest shown here is complete and fully working. It would create 5 replicas of nginx, a well-known web server.

4. Stateless Applications

Let us expore how we deploy our first application on Kubernetes, specifically a stateless application. Stateless applications are general concepts and not specific to Kubernetes, but they fit ideally into Kubernetes architecture. Stateless applications do not save any internal state or context of processed data. This means that they don't remember any previous activity or data they've handled. If such an application gets interrupted or stopped, a new replica is recreated and can start working immediately. To give an example, consider an application that queries a database. Each new query is unrelated to previous queries, so no context or history is needed.

5. Kubernetes Deployments

In Kubernetes stateless applications can be realized easily with "Kubernetes Deployments". Here, you can see a sample Manifest for such a Deployment. Let us go through the individual sections of this Manifest: `apiVersion` defines the K8s API and version to be used. For deployments, we use `apps/v1`. `kind` indicates that we will create a K8s Deployment. The `metadata` section defines various meta information we will cover later in this course. The `spec` section defines the detailed specification of our Deployment: For example, `replicas` defines the number of replicated pods the Deployment should consist of. `selector` is used to define how pods will be managed. Kubernetes will use the selector rule to find individual pods for applying changes. We will learn more about that later on in the course. Finally, `template` defines how new pods are created. If K8s decides to create a new pod for the deployment, it uses the defined template to add `labels`, create `containers` with respective `name`, docker `image`, and other details like network `ports` for communication.

6. Deploying to a Kubernetes Cluster

We use kubectl to apply the Manifest to the cluster: The command "kubectl apply -f <manifest.yml>" will send the Manifest to Kubernetes. The control Plane will decide on which node to schedule the pods, and the creation of our pods is triggered. Pods in a Deployment get a unique but random identifier. In that sense, Pods are treated as completely equal; each one is as good as any other.

7. Let's practice!

Now, let's practice what we've learned in this lesson.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.