(。◕‿‿◕。) Sylvain's blog

K8s(1) - kubectl

Apr 05, 2026

What is kubectl ?

kubectl is THE CLI to manage Kubernetes clusters. K8s objects are all represented using RESTful resources, all of which are modifiable via HTTP requests.

kubectl can make all RESTful requests (create, view, update, and delete) to resources. When viewing resources, you can get either views tailored to specific resources, or get the object representation directly in YAML, or JSON.

You will usually use YAML to make configuration files, as you can have clean, readable, usable, and easy to comment on. Or you can use JSON, where you can’t have any of that, but I guess that you can use that, if you are mentally ill. Hence why it isn’t even in bold.

YAML : clean, readable, usable, and easy to comment on (っ´ω`c)♡

JSON : ┌П┐(ಠ_ಠ)

Namespaces

Namespaces allow you to isolate resources inside a cluster. The scope of each resource is limited to resources within that same namespace, unless RBAC permissions explicitly grant access across boundaries.

Some resources are not namespaced, meaning that they are global to the cluster.

Creation of a namespace can obviously be done with kubectl:

Creating resources is done using the command create, like the following example:

$ kubectl create namespace blog-ns
namespace/blog-ns created

To get a list of resources, you can run:

$ kubectl get namespace
blog-ns           Active   35s
default           Active   342d
kube-system       Active   342d

describe is used to get the detailed view of a resource:

$ kubectl describe namespace blog-ns
Name:         blog-ns
Labels:       kubernetes.io/metadata.name=blog-ns
Annotations:  <none>
Status:       Active

No resource quota.

No LimitRange resource.

Finally you can delete it with:

$ kubectl delete namespace blog-ns
namespace "blog-ns" deleted

Notice that all of them use the syntax:

$ kubectl <action> <resource_type> <name> [flags]

To interact with resources inside a specific namespace, use the flag -n, like in the following example:

$ kubectl get pods -n blog-ns
No resources found in blog-ns namespace.

As previously mentioned, you can create YAML configuration files, here is an example:

# namespace.yaml
apiVersion: v1 # Version of K8s api used.
kind: Namespace # Type of resource.
metadata:
  name: blog-ns # Name of the namespace.

To apply this configuration just use:

$ kubectl apply -f namespace.yaml
namespace/blog-ns created

Resource names in command can often be shortened using aliases, like: ns, for namespace.

Finally, like all CLIs, you can use -h for help.

Contexts

kubectl is able to create contexts, which, as the name weirdly suggests, contain default information to use, like which cluster to connect to, user credentials, default namespace…

You can rapidly switch contexts, making it really useful if you work on multiple clusters or have multiple users with different permissions. These replace having 36 kubeconfig files.

Kubectl cheat sheet

You can get a more detailed list of all of the subcommands with: quick-references

Or as other CLIs you can use the -h flag, to get much needed help about pretty much everything, except maybe the meaning of life. (。◕‿‿◕。)


That’s all folks! Now that you can manipulate Kubernetes clusters, you can do everything you want and reach the moon, as all startups are clearly doing. See you next time for a presentation of group of whales, also known as pods in my K8s() series (づ。◕‿‿◕。)づ