I found specifying like kubectl --context dev --namespace default {other commands}
before kubectl client in many examples. Can I get a clear difference between them in a k8's environment?
A context
in Kubernetes is a group of access parameters. Each context contains a Kubernetes cluster, a user, and a namespace. The current context is the cluster that is currently the default for kubectl
: all kubectl
commands run against that cluster. Each of the context
that have been used will be available on your .kubeconfig
.
Meanwhile a namespace
is a way to support multiple virtual cluster within the same physical cluster. This usually will be related to resource quota as well as RBAC management.
You use multiple contexts to target multiple different Kubernetes clusters.You can quickly switch between clusters by using the kubectl config use-context
command.
Namespaces are a way to divide cluster resources between multiple users (via resource quota).Namespaces are intended for use in environments with many users spread across multiple teams, or projects.
A context is the connection to a specific cluster (username/apiserver host) used by kubectl. You can manage multiple clusters that way. Namespace is a logical partition inside a specific cluster to manage resources and constraints.