Every kubectl line went to the right cluster without you naming it. A file told kubectl where to go.
~/.kube/config
text
learner@shallows:~$ kubectl config view
clusters:
- cluster:
server: https://10.0.0.10:6443
name: shallows
contexts:
- context:
cluster: shallows
user: learner
name: shallows
current-context: shallows
users:
- name: learner
user:
client-certificate-data: DATA+OMITTED| Section | Holds |
|---|---|
clusters | Where each API server is |
users | How to prove who you are (certificates or tokens, Chapter 10) |
contexts | A name for one cluster plus one user, and optionally a namespace |
current-context | The context kubectl uses now |
One laptop usually has several contexts: a test cluster, a production cluster. kubectl config use-context NAME switches. Always know which one you are in:
text
learner@shallows:~$ kubectl config current-context
shallows
learner@shallows:~$ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* shallows shallows learnerA default namespace
The NAMESPACE column is empty, so every command uses default. Set it, and -n becomes optional:
text
learner@shallows:~$ kubectl config set-context --current --namespace=shop
Context "shallows" modified.
learner@shallows:~$ kubectl get pods
No resources found in shop namespace.-n still wins when you give it. Set it back with --namespace=default.