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
It will create deployment
called demo-deployments
with 3 replicas and container image jeewangautam02261995/springbootapp:v1
let's verify pods and deployment using below commands.
kubectl get deployments
kubectl get pods -o wide
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
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.
Let's run below command to verify replicas is the deployment demo-deployments
kubectl get deployments
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
Output
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
Now, we are bash terminal of demo-deployments-6f778f8c47-g7j6l
let's run whoami
to verify
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
.
Top comments (0)