Kubernetes Commands for Deployment and Management

Darcy Wood
FAUN — Developer Community 🐾
4 min readAug 1, 2022

--

A short read that demonstrates a couple of ways to use some basic Kubernetes commands to help you deploy NGINX. The first way we’ll deploy will be using only the CLI and the second will be using a YAML file. Then we’ll make some updates and finally, we will delete the project. Enjoy!

A LITTLE BACKSTORY:

Kubernetes is a robust tool that will get you orchestrating containers in no time. With it you can deploy, scale, manage, and delete applications or workloads in containers. The easiest way to work with Kubernetes is to enable it in your Docker Desktop.

You’ll need Kubectl installed as it is a command-like tool for Kubernetes that talks with the Kubernetes API server. Using Kubectl you’ll be able to launch, look at, update, and delete Kubernetes objects. After you have Kubectl installed you’ll be able to jump in and start using these commands.

CHECK VERSION. Using this will display the current running version of kubectl: kubectl version

CREATE
This command will create a deployment with an NGINX image: kubectl create deployment --image nginx <your_deployment_name>

CHECK IF DEPLOYED
This will let you see that your deployment is working: kubectl get all

SHOW PODS
Use this command to show how many pods you are running: kubectl get pods

DETAILS
This will allow you to see details of your deployment: kubectl describe deployment <your_deployment_name>

VIEW LOGS
To see what is happening in your deployment you can use this command: kubectl logs deployment/<your_deployment_name>

You’ll first want to create a new directory for your project and then create a new file for your project. You can create a new .yaml file by using the following command to open a text editor: vim <your_file_name.yaml> If you are just getting started using a text editor read this: https://opensource.com/article/19/3/getting-started-vim

Your simple YAML file can include sections like; kind, metadata, spec, selector, template, ports, and replicas (if you’d like more than one). These sections will let Kubernetes specifically what we need in our deployment. For an example of a good .yaml file and further instructions check out this link; https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

CREATE
To create the deployment using your .yaml file: kubectl apply -f <your_file_name.yaml>

CHECK
This will verify your deployment is running and will give you details of fields including; name, ready, up-to-date, available, and age: kubectl get deployments

DETAILS
To see details of your deployment use this command: kubectl describe deployments <your_deployment_name>

UPDATES
Let’s say you want to make a change to your YAML file and redeploy it. Maybe you’d like to add containers to your deployment or change ports. Simply go back into your file, make the updates, and save your changes. Then you can use the following command to redeploy: kubectl apply -f <your_file_name.yaml>

SEE REPLICASET
To see the ReplicaSets created by the deployment you can run this:
kubectl get rs

ROLLOUT STATUS. Here is a command to see the rollout status of deployment: kubectl rollout status deployment <your_deployment_name>

CLEAN UP BY DELETING YOUR DEPLOYMENTS:

If you are just trying these out and don’t want to save these deployments you can clean up and delete them using this command: kubectl delete deployment <your_deployment_name>

These are just a few commands to get you started working with Kubernetes. There are many more things you can do. If this was fun for you, I’d encourage you to dive in and get to know Kubernetes better as it could be a powerful tool as you start to manage containers that host webservers, databases, workloads, and more.

Happy Orchestrating!

All the best,
D.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

🚀Developers: Learn and grow by keeping up with what matters, JOIN FAUN.

--

--

Cloud Engineer | AWS Certified | Azure | Terraform | Python | Linux | Docker | Kubernetes