mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 14:11:14 +00:00
Replace ``shell with
``sh
This commit is contained in:
@@ -39,7 +39,7 @@ This is a toy example demonstrating how to use kubernetes DNS.
|
||||
|
||||
This example assumes that you have forked the repository and [turned up a Kubernetes cluster](../../docs/getting-started-guides/). Make sure DNS is enabled in your setup, see [DNS doc](../../cluster/addons/dns/).
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ cd kubernetes
|
||||
$ hack/dev-build-and-up.sh
|
||||
```
|
||||
@@ -48,14 +48,14 @@ $ hack/dev-build-and-up.sh
|
||||
|
||||
We'll see how cluster DNS works across multiple [namespaces](../../docs/user-guide/namespaces.md), first we need to create two namespaces:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl create -f examples/cluster-dns/namespace-dev.yaml
|
||||
$ kubectl create -f examples/cluster-dns/namespace-prod.yaml
|
||||
```
|
||||
|
||||
Now list all namespaces:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl get namespaces
|
||||
NAME LABELS STATUS
|
||||
default <none> Active
|
||||
@@ -65,7 +65,7 @@ production name=production Active
|
||||
|
||||
For kubectl client to work with each namespace, we define two contexts:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ 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}
|
||||
```
|
||||
@@ -76,14 +76,14 @@ You can view your cluster name and user name in kubernetes config at ~/.kube/con
|
||||
|
||||
Use the file [`examples/cluster-dns/dns-backend-rc.yaml`](dns-backend-rc.yaml) to create a backend server [replication controller](../../docs/user-guide/replication-controller.md) in each namespace.
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl config use-context dev
|
||||
$ kubectl create -f examples/cluster-dns/dns-backend-rc.yaml
|
||||
```
|
||||
|
||||
Once that's up you can list the pod in the cluster:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl get rc
|
||||
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
|
||||
dns-backend dns-backend ddysher/dns-backend name=dns-backend 1
|
||||
@@ -91,7 +91,7 @@ dns-backend dns-backend ddysher/dns-backend name=dns-backend 1
|
||||
|
||||
Now repeat the above commands to create a replication controller in prod namespace:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl config use-context prod
|
||||
$ kubectl create -f examples/cluster-dns/dns-backend-rc.yaml
|
||||
$ kubectl get rc
|
||||
@@ -104,14 +104,14 @@ dns-backend dns-backend ddysher/dns-backend name=dns-backend 1
|
||||
Use the file [`examples/cluster-dns/dns-backend-service.yaml`](dns-backend-service.yaml) to create
|
||||
a [service](../../docs/user-guide/services.md) for the backend server.
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl config use-context dev
|
||||
$ kubectl create -f examples/cluster-dns/dns-backend-service.yaml
|
||||
```
|
||||
|
||||
Once that's up you can list the service in the cluster:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl get service dns-backend
|
||||
NAME LABELS SELECTOR IP(S) PORT(S)
|
||||
dns-backend <none> name=dns-backend 10.0.236.129 8000/TCP
|
||||
@@ -119,7 +119,7 @@ dns-backend <none> name=dns-backend 10.0.236.129 8000/TCP
|
||||
|
||||
Again, repeat the same process for prod namespace:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl config use-context prod
|
||||
$ kubectl create -f examples/cluster-dns/dns-backend-service.yaml
|
||||
$ kubectl get service dns-backend
|
||||
@@ -131,14 +131,14 @@ dns-backend <none> name=dns-backend 10.0.35.246 8000/TCP
|
||||
|
||||
Use the file [`examples/cluster-dns/dns-frontend-pod.yaml`](dns-frontend-pod.yaml) to create a client [pod](../../docs/user-guide/pods.md) in dev namespace. The client pod will make a connection to backend and exit. Specifically, it tries to connect to address `http://dns-backend.development.cluster.local:8000`.
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl config use-context dev
|
||||
$ kubectl create -f examples/cluster-dns/dns-frontend-pod.yaml
|
||||
```
|
||||
|
||||
Once that's up you can list the pod in the cluster:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl get pods dns-frontend
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
dns-frontend 0/1 ExitCode:0 0 1m
|
||||
@@ -146,7 +146,7 @@ dns-frontend 0/1 ExitCode:0 0 1m
|
||||
|
||||
Wait until the pod succeeds, then we can see the output from the client pod:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl logs dns-frontend
|
||||
2015-05-07T20:13:54.147664936Z 10.0.236.129
|
||||
2015-05-07T20:13:54.147721290Z Send request to: http://dns-backend.development.cluster.local:8000
|
||||
@@ -158,7 +158,7 @@ Please refer to the [source code](images/frontend/client.py) about the log. Firs
|
||||
|
||||
If we switch to prod namespace with the same pod config, we'll see the same result, i.e. dns will resolve across namespace.
|
||||
|
||||
```shell
|
||||
```sh
|
||||
$ kubectl config use-context prod
|
||||
$ kubectl create -f examples/cluster-dns/dns-frontend-pod.yaml
|
||||
$ kubectl logs dns-frontend
|
||||
|
Reference in New Issue
Block a user