mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Improve console output in sharing-clusters.md doc
This commit is contained in:
parent
99d2ea4acc
commit
fddcc30683
@ -40,38 +40,38 @@ by `cluster/kube-up.sh`. Sample steps for sharing `kubeconfig` below.
|
|||||||
|
|
||||||
**1. Create a cluster**
|
**1. Create a cluster**
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
cluster/kube-up.sh
|
$ cluster/kube-up.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
**2. Copy `kubeconfig` to new host**
|
**2. Copy `kubeconfig` to new host**
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
scp $HOME/.kube/config user@remotehost:/path/to/.kube/config
|
$ scp $HOME/.kube/config user@remotehost:/path/to/.kube/config
|
||||||
```
|
```
|
||||||
|
|
||||||
**3. On new host, make copied `config` available to `kubectl`**
|
**3. On new host, make copied `config` available to `kubectl`**
|
||||||
|
|
||||||
* Option A: copy to default location
|
* Option A: copy to default location
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
mv /path/to/.kube/config $HOME/.kube/config
|
$ mv /path/to/.kube/config $HOME/.kube/config
|
||||||
```
|
```
|
||||||
|
|
||||||
* Option B: copy to working directory (from which kubectl is run)
|
* Option B: copy to working directory (from which kubectl is run)
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
mv /path/to/.kube/config $PWD
|
$ mv /path/to/.kube/config $PWD
|
||||||
```
|
```
|
||||||
|
|
||||||
* Option C: manually pass `kubeconfig` location to `.kubectl`
|
* Option C: manually pass `kubeconfig` location to `.kubectl`
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
# via environment variable
|
# via environment variable
|
||||||
export KUBECONFIG=/path/to/.kube/config
|
$ export KUBECONFIG=/path/to/.kube/config
|
||||||
|
|
||||||
# via commandline flag
|
# via commandline flag
|
||||||
kubectl ... --kubeconfig=/path/to/.kube/config
|
$ kubectl ... --kubeconfig=/path/to/.kube/config
|
||||||
```
|
```
|
||||||
|
|
||||||
## Manually Generating `kubeconfig`
|
## Manually Generating `kubeconfig`
|
||||||
@ -79,18 +79,18 @@ kubectl ... --kubeconfig=/path/to/.kube/config
|
|||||||
`kubeconfig` is generated by `kube-up` but you can generate your own
|
`kubeconfig` is generated by `kube-up` but you can generate your own
|
||||||
using (any desired subset of) the following commands.
|
using (any desired subset of) the following commands.
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
# create kubeconfig entry
|
# create kubeconfig entry
|
||||||
kubectl config set-cluster $CLUSTER_NICK
|
$ kubectl config set-cluster $CLUSTER_NICK \
|
||||||
--server=https://1.1.1.1 \
|
--server=https://1.1.1.1 \
|
||||||
--certificate-authority=/path/to/apiserver/ca_file \
|
--certificate-authority=/path/to/apiserver/ca_file \
|
||||||
--embed-certs=true \
|
--embed-certs=true \
|
||||||
# Or if tls not needed, replace --certificate-authority and --embed-certs with
|
# Or if tls not needed, replace --certificate-authority and --embed-certs with
|
||||||
--insecure-skip-tls-verify=true
|
--insecure-skip-tls-verify=true \
|
||||||
--kubeconfig=/path/to/standalone/.kube/config
|
--kubeconfig=/path/to/standalone/.kube/config
|
||||||
|
|
||||||
# create user entry
|
# create user entry
|
||||||
kubectl config set-credentials $USER_NICK
|
$ kubectl config set-credentials $USER_NICK \
|
||||||
# bearer token credentials, generated on kube master
|
# bearer token credentials, generated on kube master
|
||||||
--token=$token \
|
--token=$token \
|
||||||
# use either username|password or token, not both
|
# use either username|password or token, not both
|
||||||
@ -98,11 +98,11 @@ kubectl config set-credentials $USER_NICK
|
|||||||
--password=$password \
|
--password=$password \
|
||||||
--client-certificate=/path/to/crt_file \
|
--client-certificate=/path/to/crt_file \
|
||||||
--client-key=/path/to/key_file \
|
--client-key=/path/to/key_file \
|
||||||
--embed-certs=true
|
--embed-certs=true \
|
||||||
--kubeconfig=/path/to/standalone/.kubeconfig
|
--kubeconfig=/path/to/standalone/.kubeconfig
|
||||||
|
|
||||||
# create context entry
|
# create context entry
|
||||||
kubectl config set-context $CONTEXT_NAME --cluster=$CLUSTER_NICKNAME --user=$USER_NICK
|
$ kubectl config set-context $CONTEXT_NAME --cluster=$CLUSTER_NICKNAME --user=$USER_NICK
|
||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
@ -112,8 +112,8 @@ Notes:
|
|||||||
save config too. In the above commands the `--kubeconfig` file could be
|
save config too. In the above commands the `--kubeconfig` file could be
|
||||||
omitted if you first run
|
omitted if you first run
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
export KUBECONFIG=/path/to/standalone/.kube/config
|
$ export KUBECONFIG=/path/to/standalone/.kube/config
|
||||||
```
|
```
|
||||||
|
|
||||||
* The ca_file, key_file, and cert_file referenced above are generated on the
|
* The ca_file, key_file, and cert_file referenced above are generated on the
|
||||||
@ -135,16 +135,16 @@ and/or run `kubectl config -h`.
|
|||||||
If you create clusters A, B on host1, and clusters C, D on host2, you can
|
If you create clusters A, B on host1, and clusters C, D on host2, you can
|
||||||
make all four clusters available on both hosts by running
|
make all four clusters available on both hosts by running
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
# on host2, copy host1's default kubeconfig, and merge it from env
|
# on host2, copy host1's default kubeconfig, and merge it from env
|
||||||
scp host1:/path/to/home1/.kube/config path/to/other/.kube/config
|
$ scp host1:/path/to/home1/.kube/config path/to/other/.kube/config
|
||||||
|
|
||||||
export $KUBECONFIG=path/to/other/.kube/config
|
$ export $KUBECONFIG=path/to/other/.kube/config
|
||||||
|
|
||||||
# on host1, copy host2's default kubeconfig and merge it from env
|
# on host1, copy host2's default kubeconfig and merge it from env
|
||||||
scp host2:/path/to/home2/.kube/config path/to/other/.kube/config
|
$ scp host2:/path/to/home2/.kube/config path/to/other/.kube/config
|
||||||
|
|
||||||
export $KUBECONFIG=path/to/other/.kube/config
|
$ export $KUBECONFIG=path/to/other/.kube/config
|
||||||
```
|
```
|
||||||
|
|
||||||
Detailed examples and explanation of `kubeconfig` loading/merging rules can be found in [kubeconfig-file.md](kubeconfig-file.md).
|
Detailed examples and explanation of `kubeconfig` loading/merging rules can be found in [kubeconfig-file.md](kubeconfig-file.md).
|
||||||
|
Loading…
Reference in New Issue
Block a user