2015-07-12 04:04:52 +00:00
|
|
|
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
|
|
|
|
|
|
|
<!-- BEGIN STRIP_FOR_RELEASE -->
|
|
|
|
|
2015-07-16 17:02:26 +00:00
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
|
|
|
|
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
|
|
|
|
|
|
|
|
If you are using a released version of Kubernetes, you should
|
|
|
|
refer to the docs that go with that version.
|
|
|
|
|
2015-12-14 18:37:38 +00:00
|
|
|
<!-- TAG RELEASE_LINK, added by the munger automatically -->
|
2015-07-16 17:02:26 +00:00
|
|
|
<strong>
|
2015-11-03 18:17:57 +00:00
|
|
|
The latest release of this document can be found
|
|
|
|
[here](http://releases.k8s.io/release-1.1/docs/user-guide/sharing-clusters.md).
|
2015-07-16 17:02:26 +00:00
|
|
|
|
|
|
|
Documentation for other releases can be found at
|
|
|
|
[releases.k8s.io](http://releases.k8s.io).
|
|
|
|
</strong>
|
|
|
|
--
|
2015-07-13 22:15:35 +00:00
|
|
|
|
2015-07-12 04:04:52 +00:00
|
|
|
<!-- END STRIP_FOR_RELEASE -->
|
|
|
|
|
|
|
|
<!-- END MUNGE: UNVERSIONED_WARNING -->
|
2015-07-17 22:35:41 +00:00
|
|
|
|
2015-03-16 20:05:52 +00:00
|
|
|
# Sharing Cluster Access
|
|
|
|
|
2015-07-20 20:45:36 +00:00
|
|
|
Client access to a running Kubernetes cluster can be shared by copying
|
2015-09-16 12:53:05 +00:00
|
|
|
the `kubectl` client config bundle ([kubeconfig](kubeconfig-file.md)).
|
2015-04-17 21:04:14 +00:00
|
|
|
This config bundle lives in `$HOME/.kube/config`, and is generated
|
|
|
|
by `cluster/kube-up.sh`. Sample steps for sharing `kubeconfig` below.
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
**1. Create a cluster**
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
|
|
|
$ cluster/kube-up.sh
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-04-17 21:04:14 +00:00
|
|
|
**2. Copy `kubeconfig` to new host**
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
|
|
|
$ scp $HOME/.kube/config user@remotehost:/path/to/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
|
|
|
|
2015-04-17 21:04:14 +00:00
|
|
|
**3. On new host, make copied `config` available to `kubectl`**
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
* Option A: copy to default location
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
|
|
|
$ mv /path/to/.kube/config $HOME/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-03-16 20:05:52 +00:00
|
|
|
* Option B: copy to working directory (from which kubectl is run)
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
|
|
|
$ mv /path/to/.kube/config $PWD
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-09-16 12:53:05 +00:00
|
|
|
* Option C: manually pass `kubeconfig` location to `kubectl`
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
2015-03-16 20:05:52 +00:00
|
|
|
# via environment variable
|
2015-07-19 00:46:32 +00:00
|
|
|
$ export KUBECONFIG=/path/to/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
# via commandline flag
|
2015-07-19 00:46:32 +00:00
|
|
|
$ kubectl ... --kubeconfig=/path/to/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
|
|
|
|
2015-04-17 21:04:14 +00:00
|
|
|
## Manually Generating `kubeconfig`
|
2015-03-16 20:05:52 +00:00
|
|
|
|
2015-04-17 21:04:14 +00:00
|
|
|
`kubeconfig` is generated by `kube-up` but you can generate your own
|
2015-03-16 20:05:52 +00:00
|
|
|
using (any desired subset of) the following commands.
|
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
2015-03-16 20:05:52 +00:00
|
|
|
# create kubeconfig entry
|
2015-07-19 00:46:32 +00:00
|
|
|
$ kubectl config set-cluster $CLUSTER_NICK \
|
2015-03-16 20:05:52 +00:00
|
|
|
--server=https://1.1.1.1 \
|
|
|
|
--certificate-authority=/path/to/apiserver/ca_file \
|
|
|
|
--embed-certs=true \
|
|
|
|
# Or if tls not needed, replace --certificate-authority and --embed-certs with
|
2015-07-19 00:46:32 +00:00
|
|
|
--insecure-skip-tls-verify=true \
|
2015-04-17 21:04:14 +00:00
|
|
|
--kubeconfig=/path/to/standalone/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
# create user entry
|
2015-07-19 00:46:32 +00:00
|
|
|
$ kubectl config set-credentials $USER_NICK \
|
2015-04-17 21:04:14 +00:00
|
|
|
# bearer token credentials, generated on kube master
|
|
|
|
--token=$token \
|
|
|
|
# use either username|password or token, not both
|
2015-03-16 20:05:52 +00:00
|
|
|
--username=$username \
|
|
|
|
--password=$password \
|
|
|
|
--client-certificate=/path/to/crt_file \
|
|
|
|
--client-key=/path/to/key_file \
|
2015-07-19 00:46:32 +00:00
|
|
|
--embed-certs=true \
|
2015-09-16 12:53:05 +00:00
|
|
|
--kubeconfig=/path/to/standalone/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
# create context entry
|
2015-07-19 00:46:32 +00:00
|
|
|
$ kubectl config set-context $CONTEXT_NAME --cluster=$CLUSTER_NICKNAME --user=$USER_NICK
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-03-16 20:05:52 +00:00
|
|
|
Notes:
|
|
|
|
* The `--embed-certs` flag is needed to generate a standalone
|
2015-04-17 21:04:14 +00:00
|
|
|
`kubeconfig`, that will work as-is on another host.
|
2015-03-16 20:05:52 +00:00
|
|
|
* `--kubeconfig` is both the preferred file to load config from and the file to
|
|
|
|
save config too. In the above commands the `--kubeconfig` file could be
|
|
|
|
omitted if you first run
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
|
|
|
$ export KUBECONFIG=/path/to/standalone/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-04-27 02:37:14 +00:00
|
|
|
* The ca_file, key_file, and cert_file referenced above are generated on the
|
2015-03-16 20:05:52 +00:00
|
|
|
kube master at cluster turnup. They can be found on the master under
|
2015-04-17 21:04:14 +00:00
|
|
|
`/srv/kubernetes`. Bearer token/basic auth are also generated on the kube master.
|
2015-03-16 20:05:52 +00:00
|
|
|
|
2015-04-17 21:04:14 +00:00
|
|
|
For more details on `kubeconfig` see [kubeconfig-file.md](kubeconfig-file.md),
|
2015-03-16 20:05:52 +00:00
|
|
|
and/or run `kubectl config -h`.
|
|
|
|
|
2015-04-17 21:04:14 +00:00
|
|
|
## Merging `kubeconfig` Example
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
`kubectl` loads and merges config from the following locations (in order)
|
|
|
|
|
2015-09-16 12:53:05 +00:00
|
|
|
1. `--kubeconfig=/path/to/.kube/config` command line flag
|
|
|
|
2. `KUBECONFIG=/path/to/.kube/config` env variable
|
|
|
|
3. `$PWD/.kube/config`
|
2015-04-17 21:04:14 +00:00
|
|
|
4. `$HOME/.kube/config`
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-07-19 00:46:32 +00:00
|
|
|
```console
|
2015-03-16 20:05:52 +00:00
|
|
|
# on host2, copy host1's default kubeconfig, and merge it from env
|
2015-09-16 12:53:05 +00:00
|
|
|
$ scp host1:/path/to/home1/.kube/config /path/to/other/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
|
2015-09-16 12:53:05 +00:00
|
|
|
$ export $KUBECONFIG=/path/to/other/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
|
|
|
|
# on host1, copy host2's default kubeconfig and merge it from env
|
2015-09-16 12:53:05 +00:00
|
|
|
$ scp host2:/path/to/home2/.kube/config /path/to/other/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
|
2015-09-16 12:53:05 +00:00
|
|
|
$ export $KUBECONFIG=/path/to/other/.kube/config
|
2015-03-16 20:05:52 +00:00
|
|
|
```
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-07-10 01:02:10 +00:00
|
|
|
Detailed examples and explanation of `kubeconfig` loading/merging rules can be found in [kubeconfig-file.md](kubeconfig-file.md).
|
2015-03-16 20:05:52 +00:00
|
|
|
|
2015-05-14 22:12:45 +00:00
|
|
|
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
2015-07-14 16:37:37 +00:00
|
|
|
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/sharing-clusters.md?pixel)]()
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- END MUNGE: GENERATED_ANALYTICS -->
|