Skip to content

Commit 71389e6

Browse files
authored
Merge pull request #31604 from neolit123/1.24-add-example-for-kubeconfig-user
kubeadm: add missing guide for "kubeconfig user"
2 parents 76429c1 + 75a33b2 commit 71389e6

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

content/en/docs/reference/setup-tools/kubeadm/kubeadm-kubeconfig.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ weight: 90
66

77
`kubeadm kubeconfig` provides utilities for managing kubeconfig files.
88

9+
For examples on how to use `kubeadm kubeconfig user` see
10+
[Generating kubeconfig files for additional users](/docs/tasks/administer-cluster/kubeadm/kubeadm-certs#kubeconfig-additional-users).
11+
912
## kubeadm kubeconfig {#cmd-kubeconfig}
1013

1114
{{< tabs name="tab-kubeconfig" >}}

content/en/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ export KUBECONFIG=/etc/kubernetes/admin.conf
210210
Kubeadm signs the certificate in the `admin.conf` to have `Subject: O = system:masters, CN = kubernetes-admin`.
211211
`system:masters` is a break-glass, super user group that bypasses the authorization layer (e.g. RBAC).
212212
Do not share the `admin.conf` file with anyone and instead grant users custom permissions by generating
213-
them a kubeconfig file using the `kubeadm kubeconfig user` command.
213+
them a kubeconfig file using the `kubeadm kubeconfig user` command. For more details see
214+
[Generating kubeconfig files for additional users](/docs/tasks/administer-cluster/kubeadm/kubeadm-certs#kubeconfig-additional-users).
214215
{{< /warning >}}
215216

216217
Make a record of the `kubeadm join` command that `kubeadm init` outputs. You
@@ -384,8 +385,8 @@ A few seconds later, you should notice this node in the output from `kubectl get
384385
nodes` when run on the control-plane node.
385386

386387
{{< note >}}
387-
As the cluster nodes are usually initialized sequentially, the CoreDNS Pods are likely to all run
388-
on the first control-plane node. To provide higher availability, please rebalance the CoreDNS Pods
388+
As the cluster nodes are usually initialized sequentially, the CoreDNS Pods are likely to all run
389+
on the first control-plane node. To provide higher availability, please rebalance the CoreDNS Pods
389390
with `kubectl -n kube-system rollout restart deployment coredns` after at least one new node is joined.
390391
{{< /note >}}
391392

content/en/docs/tasks/administer-cluster/kubeadm/kubeadm-certs.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ weight: 10
1010

1111
{{< feature-state for_k8s_version="v1.15" state="stable" >}}
1212

13-
Client certificates generated by [kubeadm](/docs/reference/setup-tools/kubeadm/) expire after 1 year. This page explains how to manage certificate renewals with kubeadm.
13+
Client certificates generated by [kubeadm](/docs/reference/setup-tools/kubeadm/) expire after 1 year.
14+
This page explains how to manage certificate renewals with kubeadm. It also covers other tasks related
15+
to kubeadm certificate management.
1416

1517
## {{% heading "prerequisites" %}}
1618

@@ -126,13 +128,13 @@ command. In that case, you should explicitly set `--certificate-renewal=true`.
126128

127129
You can renew your certificates manually at any time with the `kubeadm certs renew` command.
128130

129-
This command performs the renewal using CA (or front-proxy-CA) certificate and key stored in `/etc/kubernetes/pki`.
131+
This command performs the renewal using CA (or front-proxy-CA) certificate and key stored in `/etc/kubernetes/pki`.
130132

131133
After running the command you should restart the control plane Pods. This is required since
132134
dynamic certificate reload is currently not supported for all components and certificates.
133135
[Static Pods](/docs/tasks/configure-pod-container/static-pod/) are managed by the local kubelet
134136
and not by the API Server, thus kubectl cannot be used to delete and restart them.
135-
To restart a static Pod you can temporarily remove its manifest file from `/etc/kubernetes/manifests/`
137+
To restart a static Pod you can temporarily remove its manifest file from `/etc/kubernetes/manifests/`
136138
and wait for 20 seconds (see the `fileCheckFrequency` value in [KubeletConfiguration struct](/docs/reference/config-api/kubelet-config.v1beta1/).
137139
The kubelet will terminate the Pod if it's no longer in the manifest directory.
138140
You can then move the file back and after another `fileCheckFrequency` period, the kubelet will recreate
@@ -289,3 +291,52 @@ Such a controller is not a secure mechanism unless it not only verifies the Comm
289291
in the CSR but also verifies the requested IPs and domain names. This would prevent
290292
a malicious actor that has access to a kubelet client certificate to create
291293
CSRs requesting serving certificates for any IP or domain name.
294+
295+
## Generating kubeconfig files for additional users {#kubeconfig-additional-users}
296+
297+
During cluster creation, kubeadm signs the certificate in the `admin.conf` to have
298+
`Subject: O = system:masters, CN = kubernetes-admin`.
299+
[`system:masters`](/docs/reference/access-authn-authz/rbac/#user-facing-roles)
300+
is a break-glass, super user group that bypasses the authorization layer (e.g. RBAC).
301+
Sharing the `admin.conf` with additional users is **not recommended**!
302+
303+
Instead, you can use the [`kubeadm kubeconfig user`](/docs/reference/setup-tools/kubeadm/kubeadm-kubeconfig)
304+
command to generate kubeconfig files for additional users.
305+
The command accepts a mixture of command line flags and
306+
[kubeadm configuration](/docs/reference/config-api/kubeadm-config.v1beta3/) options.
307+
The generated kubeconfig will be written to stdout and can be piped to a file
308+
using `kubeadm kubeconfig user ... > somefile.conf`.
309+
310+
Example configuration file that can be used with `--config`:
311+
312+
```yaml
313+
# example.yaml
314+
apiVersion: kubeadm.k8s.io/v1beta3
315+
kind: ClusterConfiguration
316+
# Will be used as the target "cluster" in the kubeconfig
317+
clusterName: "kubernetes"
318+
# Will be used as the "server" (IP or DNS name) of this cluster in the kubeconfig
319+
controlPlaneEndpoint: "some-dns-address:6443"
320+
# The cluster CA key and certificate will be loaded from this local directory
321+
certificatesDir: "/etc/kubernetes/pki"
322+
```
323+
324+
Make sure that these settings match the desired target cluster settings.
325+
To see the settings of an existing cluster use:
326+
327+
```shell
328+
kubectl get cm kubeadm-config -n kube-system -o=jsonpath="{.data.ClusterConfiguration}"
329+
```
330+
331+
The following example will generate a kubeconfig file with credentials valid for 24 hours
332+
for a new user `johndoe` that is part of the `appdevs` group:
333+
334+
```shell
335+
kubeadm kubeconfig user --config example.yaml --org appdevs --client-name johndoe --validity-period 24h
336+
```
337+
338+
The following example will generate a kubeconfig file with administrator credentials valid for 1 week:
339+
340+
```shell
341+
kubeadm kubeconfig user --config example.yaml --client-name admin --validity-period 168h
342+
```

0 commit comments

Comments
 (0)