Top 10 Commands of Kubernetes You Need

It may seem daunting to run kubernetes commands, but once you learned its main components, the rest is just about learning the syntax to tell kubernetes what you want to do.

1. Main Components of K8s

We all know K8s is an orchestration tool, but what does that mean exactly? The most basic understanding can be: it allows you to define what resources you need, and how they are allocated to different workloads. K8s not only lets you set those things up, it helps you to monitor and maintain all the services you desires. To own this power, K8S has its own pre-defined structure so you can write scripts based on it.

2. Two Approaches To Give K8s Commands

There are two ways to communicate with K8S:

(1) Declarative VS Imperative

Declarative means you tell k8s what you want, and you don’t care how it gets it for you, it will always maintain the desired state itself. If you have a clear defined system already, you can use this.

(2) Yaml VS Command line

If you have used yaml before, yes, it works the same way! It is a preferred approach if you want to give any command with some complexity simply because it is written in a file, it then becomes easier for you to check everything. Also, there are some functions of k8s simply are not supported by command line (e.x. customizing some port number). So it’s your time to pick up yaml! It’s similar to JSON, just has a bit more syntaxt and data structure, but all are very basic and readable once you are willing to spend some time to learn!

3. Top 10 Frequently Used Commands

  1. eksctl create cluster/nodegroup => create the cluster or the nodegroup
  2. eksctl utils associate-iam-oidc-provider => associate OIDC provider so you can use AWS IAM roles later down the road
  3. kubectl get pods/service/deployment/nodes/quota/limits
  4. kubectl get nodes -o wide => when you need to see your external IP
  5. kubectl create -f filename.yml => declarative
  6. kubectl apply -f filename.yml => imperative
  7. kubectl apply -f folder-name/ => apply all the yaml files in this folder
  8. kubectl describe pods/svc/nodes/deployment/limit/quota => current details of your object
  9. kubectl get logs your-pod-id => details of what you did to this object
  10. kubectl delete pod/svc/deployment name-of-your-object => if you give commands in declarative way, k8s will delete then recreate to maintain the desired state.

I am a Machine Learning Engineer with special interest in mental health and finance.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store