Improve k8s DNS example usability (#164)
the command in example should be straightforward asap, user just do copy and paste to move on. This change is align with spark example to set CLUSTER_NAME and USER_NAME, refer to below link for the details: https://github.com/kubernetes/examples/tree/master/staging/spark
This commit is contained in:
parent
0b2b574d31
commit
cee89cecb7
|
@ -30,15 +30,16 @@ development name=development Active
|
||||||
production name=production Active
|
production name=production Active
|
||||||
```
|
```
|
||||||
|
|
||||||
For kubectl client to work with each namespace, we define two contexts:
|
For kubectl client to work with each namespace, we define two contexts using our current context as a base:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
$ CURRENT_CONTEXT=$(kubectl config view -o jsonpath='{.current-context}')
|
||||||
|
$ USER_NAME=$(kubectl config view -o jsonpath='{.contexts[?(@.name == "'"${CURRENT_CONTEXT}"'")].context.user}')
|
||||||
|
$ CLUSTER_NAME=$(kubectl config view -o jsonpath='{.contexts[?(@.name == "'"${CURRENT_CONTEXT}"'")].context.cluster}')
|
||||||
$ kubectl config set-context dev --namespace=development --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
$ kubectl config set-context dev --namespace=development --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
||||||
$ kubectl config set-context prod --namespace=production --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
$ kubectl config set-context prod --namespace=production --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can view your cluster name and user name in Kubernetes config at ~/.kube/config.
|
|
||||||
|
|
||||||
### Step Two: Create backend replication controller in each namespace
|
### Step Two: Create backend replication controller in each namespace
|
||||||
|
|
||||||
Use the file [`examples/cluster-dns/dns-backend-rc.yaml`](dns-backend-rc.yaml) to create a backend server [replication controller](https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/) in each namespace.
|
Use the file [`examples/cluster-dns/dns-backend-rc.yaml`](dns-backend-rc.yaml) to create a backend server [replication controller](https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/) in each namespace.
|
||||||
|
@ -143,7 +144,7 @@ If you prefer not using namespace, then all your services can be addressed using
|
||||||
|
|
||||||
### tl; dr;
|
### tl; dr;
|
||||||
|
|
||||||
For those of you who are impatient, here is the summary of the commands we ran in this tutorial. Remember to set first `$CLUSTER_NAME` and `$USER_NAME` to the values found in `~/.kube/config`.
|
For those of you who are impatient, here is the summary of the commands we ran in this tutorial. Remember the values of `$CLUSTER_NAME` and `$USER_NAME` are based on current context found in `~/.kube/config`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# create dev and prod namespaces
|
# create dev and prod namespaces
|
||||||
|
@ -151,6 +152,9 @@ kubectl create -f examples/cluster-dns/namespace-dev.yaml
|
||||||
kubectl create -f examples/cluster-dns/namespace-prod.yaml
|
kubectl create -f examples/cluster-dns/namespace-prod.yaml
|
||||||
|
|
||||||
# create two contexts
|
# create two contexts
|
||||||
|
CURRENT_CONTEXT=$(kubectl config view -o jsonpath='{.current-context}')
|
||||||
|
USER_NAME=$(kubectl config view -o jsonpath='{.contexts[?(@.name == "'"${CURRENT_CONTEXT}"'")].context.user}')
|
||||||
|
CLUSTER_NAME=$(kubectl config view -o jsonpath='{.contexts[?(@.name == "'"${CURRENT_CONTEXT}"'")].context.cluster}')
|
||||||
kubectl config set-context dev --namespace=development --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
kubectl config set-context dev --namespace=development --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
||||||
kubectl config set-context prod --namespace=production --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
kubectl config set-context prod --namespace=production --cluster=${CLUSTER_NAME} --user=${USER_NAME}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue