Mastering Stateless Application Deployment: A Step-by-Step Guide"

Mastering Stateless Application Deployment: A Step-by-Step Guide"

Introduction:

Hey there! Ever wondered how your favorite apps run so smoothly without crashing? Well, it's all about deploying them right! In this easy-to-follow blog post, we'll walk you through the basics of running your app without getting tangled up in technical jargon. Let's dive in!

What's a Stateless App?

Okay, imagine you're at a food truck festival. You order a taco from one truck and then move on to the next for a burger. Each time you order, the truck doesn't remember your previous order. That's exactly how a stateless app works! It doesn't keep track of your past interactions. It's like a clean slate every time you use it.

Why Deployment Matters:

Now, let's talk about deployment. Think of deployment as setting up a stall at a fair. You want to make sure your stall is easy to find, runs smoothly, and serves everyone quickly. Deployment is how you do that with your app. It's about making sure your app is available to everyone without crashing or slowing down.

Objectives

  • Create an nginx deployment.

  • Use kubectl to list information about the deployment.

  • Update the deployment.

Steps:

kindly create a project folder named "application" or whatever you name it. After moving into the newly created folder. Create a new yaml file called "deployment.yaml" whose content is listed below for your reference.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

The very next step would be to save your file and apply it using the command

kubectl apply -f deployment.yaml

We can describe the deployment using the command

kubectl describe deployment nginx-deployment

If you want to list the pods , we can see this information using the command

kubectl get pods

But to see the specific pods which are only build by "nginx-deployment",

we would input the command as

kubectl get pods -l app=nginx

To see the information about any pods , we can simply do that by

kubectl describe pod <pod-name>

Updating the Deployment

You can update the deployment by applying a new YAML file. This YAML file specifies that the deployment should be updated to use nginx 1.16.1. The before yaml file states nginx version of 1.14.2.

Change the version by going into the vim editor

vim mysql-deployment.yaml

kindly save it by pressing "esc + :wq"
and reapply this file forcefully

kubectl apply -f mysql-deployment.yaml

We can see the pods again as shown above.

Scaling the application by increasing the replica count

currently we have two pods running for nginx-deployment

But we will scale our replica count to 4 for our deployment file for a new yaml file.

kindly change the number of replica to 4 and reapply it forcefully.

Deleting the deployment

After all the process and operations done by us should be deleted too.

kindly delete the deployment by command

kubectl delete deployment deploymentName

Conclusion

And there you have it! You've successfully set up your app for success without breaking a sweat. Remember, deployment doesn't have to be daunting. With the right approach and a bit of patience, you can have your app up and running smoothly in no time. Happy deploying!

In the face of every storm, he stands unbroken, for his resilience knows no bounds, his spirit never wavers.

Did you find this article valuable?

Support CodeAryan by becoming a sponsor. Any amount is appreciated!