In this post we’ll learn some of the most useful and important Kubernetes System commands that you should know before diving deeper into kubectl cli.


Kubernetes Config

Probably the most important command which kind of sits above anything else you’ll explore on the Kubernetes cluster. If you don’t know config then you won’t even be able to browse your clusters, also known as contexts. So in this section we’ll talk about Kubernetes Contexts.

More details: kubectl config

Show Current Context

kubectl config current-context

List All Contexts

kubectl config get-contexts

Switch to Context

kubectl config use-contexts [CONTEXT NAME]

Delete Context

kubectl config delete-context [CLUSTER NAME]

Clear .kube File

kubectl config unset users.[CLUSTER USER]
kubectl config unset contexts.[CONTEXT NAME]
kubectl config unset clusters.[CLUSTER NAME]

Kubernetes Cluster

We’ll now start looking into your chosen cluster and we’ll start with inspecting the cluster-info details.

More details: kubectl cluster-info

High Level Cluster Info

kubectl cluster-info

Low Level Cluster Info Dump

kubectl cluster-info dump

Kubernetes Cluster Nodes

Once you made into your chosen context, you’ll probably need to see what the cluster is made of, how many Nodes are running as well as node details, such as cpu, memory, pod capacity, versions etc.

More details: Kubernetes Nodes

List All Nodes

kubectl get nodes

Describe All Nodes

kubectl describe nodes

Describe Single Node

kubectl describe node [NODE NAME]

Kubernetes Cluster Events

At this point you know your cluster quite well so it’s time to start looking into what’s actually happening on the cluster. This information is normally shown as Events.

List All Events

kubectl get events

List Events per Namespace

kubectl get events -n [NAMESPACE]

Kubernetes Namespaces

We’ll start wrapping up this chapter with a seamless transition from cluster information to workloads running on the cluster. And the best start on that is with learning Namespaces, which are essentially buckets into which your applications will deployed into.

More details: Kubernetes Namespaces

Create Namespace

Imperative

kubectl create ns [NAME]

Declarative

kubectl apply -f [NAMESPACE TEMPLATE].yaml

[NAMESPACE TEMPLATE].yaml

apiVersion: v1
kind: Namespace
metadata:
  name: [NAME]

List All Namespaces

kubectl get namespaces

Show All Resources in Namespace

kubectl get all -n [NAMESPACE]

Show All Resources in All Namespaces

kubectl get all --all-namespaces

Delete Namespace

Imperative

kubectl delete ns [NAME]

Declarative

kubectl delete -f [NAMESPACE TEMPLATE].yaml

Kubernetes Server Resources

Finally, to complement Namespaces, we’ll now discover which Kubernetes resources are available on your cluster as well as information whether these can be bound into a namespace or not.

More details: kubectl api-resources

List Server Resource Types

kubectl api-resources

<< Introduction | Kubernetes System | Kubernetes Pods >>

Marcin Narloch

Marcin Narloch

Creative and out-of-the-box thinker with strong interests and knowledge in technology and innovation.
Docker Building Blocks Previous post Kubernetes Pods
Docker Building Blocks Next post Introduction

Leave a Reply

Your email address will not be published.