From ae4525f38f00c15c9c6d8a72fece945b10f47901 Mon Sep 17 00:00:00 2001 From: Qiming Teng Date: Tue, 2 Jan 2018 11:28:07 +0800 Subject: [PATCH] Add text about namespace walkthrough Closes: #4270 --- .../namespaces-walkthrough.md | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/docs/tasks/administer-cluster/namespaces-walkthrough.md b/docs/tasks/administer-cluster/namespaces-walkthrough.md index 399a6fe230..efd7b517de 100644 --- a/docs/tasks/administer-cluster/namespaces-walkthrough.md +++ b/docs/tasks/administer-cluster/namespaces-walkthrough.md @@ -63,6 +63,10 @@ Create the development namespace using kubectl. $ kubectl create -f https://k8s.io/docs/tasks/administer-cluster/namespace-dev.json ``` +Save the following contents into file [`namespace-prod.json`](/docs/admin/namespaces/namespace-prod.json) which describes a production namespace: + +{% include code.html language="json" file="namespace-prod.json" ghlink="/docs/tasks/administer-cluster/namespace-prod.json" %} + And then let's create the production namespace using kubectl. ```shell @@ -123,12 +127,57 @@ lithe-cocoa-92103_kubernetes The next step is to define a context for the kubectl client to work in each namespace. The value of "cluster" and "user" fields are copied from the current context. ```shell -$ kubectl config set-context dev --namespace=development --cluster=lithe-cocoa-92103_kubernetes --user=lithe-cocoa-92103_kubernetes -$ kubectl config set-context prod --namespace=production --cluster=lithe-cocoa-92103_kubernetes --user=lithe-cocoa-92103_kubernetes +$ kubectl config set-context dev --namespace=development \ + --cluster=lithe-cocoa-92103_kubernetes \ + --user=lithe-cocoa-92103_kubernetes +$ kubectl config set-context prod --namespace=production \ + --cluster=lithe-cocoa-92103_kubernetes \ + --user=lithe-cocoa-92103_kubernetes ``` -The above commands provided two request contexts you can alternate against depending on what namespace you -wish to work against. +By default, the above commands adds two contexts that are saved into file +`.kube/config`. You can now view the contexts and alternate against the two +new request contexts depending on which namespace you wish to work against. + +To view the new contexts: + +```shell +$ kubectl config view +apiVersion: v1 +clusters: +- cluster: + certificate-authority-data: REDACTED + server: https://130.211.122.180 + name: lithe-cocoa-92103_kubernetes +contexts: +- context: + cluster: lithe-cocoa-92103_kubernetes + user: lithe-cocoa-92103_kubernetes + name: lithe-cocoa-92103_kubernetes +- context: + cluster: lithe-cocoa-92103_kubernetes + namespace: development + user: lithe-cocoa-92103_kubernetes + name: dev +- context: + cluster: lithe-cocoa-92103_kubernetes + namespace: production + user: lithe-cocoa-92103_kubernetes + name: prod +current-context: lithe-cocoa-92103_kubernetes +kind: Config +preferences: {} +users: +- name: lithe-cocoa-92103_kubernetes + user: + client-certificate-data: REDACTED + client-key-data: REDACTED + token: 65rZW78y8HbwXXtSXuUw9DbP4FLjHi4b +- name: lithe-cocoa-92103_kubernetes-basic-auth + user: + password: h5M0FtUUIflBSdI7 + username: admin + Let's switch to operate in the development namespace.