Goglides Dev 🌱

Goglides Dev 🌱 is a community of amazing users

We are working on this space so that IT professionals can grow together.

Create account Log in
Jeewan Gautam
Jeewan Gautam

Posted on • Updated on

Process to deploy application in k8s using Deployment object without using YAML.

In previous blog we discussed how to create and update deployments using YAML definition. Here, we will be using various commands. let's start.

Let's run kubectl create command with various parameters to create deployment.

Example

kubectl create deployment demo-deployments --replicas=3 --image=jeewangautam02261995/springbootapp:v1
Enter fullscreen mode Exit fullscreen mode

It will create deployment called demo-deployments with 3 replicas and container image jeewangautam02261995/springbootapp:v1

Output
Image description

let's verify pods and deployment using below commands.

kubectl get deployments 
Enter fullscreen mode Exit fullscreen mode

Output
Image description

kubectl get pods -o wide 
Enter fullscreen mode Exit fullscreen mode

Output
Image description

Updating the deployment using commands.

Let's discuss how we can scale up and down our deployment using command.

Run below command to scale up deployment 'demo-deployments'.

kubectl edit deploy demo-deployments
Enter fullscreen mode Exit fullscreen mode

You will see something like this. You can edit anything as per your requirements in this file. Here, we are going to scale our replica from 3 to 4.

Output
Image description
Image description

Let's run below command to verify replicas is the deployment demo-deployments

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

Output
Image description

We can scale down the replica by reducing the replica's value.

Now let's try kubectl scale command to scale our deployment.You can scale deployment with out touching YAML file. let's try!

kubectl scale deploy demo-deployments --replicas=2
Enter fullscreen mode Exit fullscreen mode

Output
Image description
Here, we can see we scaled down demo-deployments to 2 replica set.

how to attach inside the container and install some of the packages?

As you know, we can perform various operation in container using different shells. For example, let enter to one of the demo-deployments container by running below commands.

kubectl exec -it demo-deployments-6f778f8c47-g7j6l -- bash
Enter fullscreen mode Exit fullscreen mode

Output
Image description

Now, we are bash terminal of demo-deployments-6f778f8c47-g7j6l let's run whoami to verify

Image description

Image description

Now, we are in bash terminal inside container. But in my case I am using openkdk:jdk as base image and would not able perform any action inside the container like, installing, updating software. As it's trying to improve security by removing all the package managers from the image.
if you are using ubuntu or busybox as base image you should able to perform some action inside container. In the next, section we will deploy application with base image as ubuntu.

Discussion (0)