Skip to content

Commit 6c31c0e

Browse files
committed
Update external etcd documentation
Re-organize content for easier reading. Update commands for creating Secrets. Fix incorrect reference to etcd server certificate. Add section on potential caveats for various CAPI providers. Signed-off-by: Scott Lowe <[email protected]>
1 parent 18ce96a commit 6c31c0e

File tree

1 file changed

+54
-27
lines changed

1 file changed

+54
-27
lines changed

Diff for: bootstrap/kubeadm/docs/external-etcd.md

+54-27
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,76 @@
11
# Support for external etcd
22

3-
Cluster API Bootstrap Provider Kubeadm supports using an external etcd cluster for your workload Kubernetes clusters.
3+
Cluster API Bootstrap Provider Kubeadm supports using an external etcd cluster for your workload Kubernetes clusters.
44

55
## ⚠️ Warnings ⚠️
66

77
Before getting started you should be aware of the expectations that come with using an external etcd cluster.
88

99
* Cluster API is unable to manage any aspect of the external etcd cluster.
1010
* Depending on how you configure your etcd nodes you may incur additional cloud costs in data transfer.
11-
* As an example, cross availability zone traffic can cost money on cloud providers. You don't have to deploy etcd
12-
across availability zones, but if you do please be aware of the costs.
11+
* As an example, cross availability zone traffic can cost money on cloud providers. You don't have to deploy etcd across availability zones, but if you do please be aware of the costs.
1312

1413
## Getting started
1514

16-
To use this, you will need to create an etcd cluster and generate an apiserver-etcd-client key/pair.
17-
This behaviour can be tested using [`kubeadm`](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/setup-ha-etcd-with-kubeadm/) and [`etcdadm`](https://github.com/kubernetes-sigs/etcdadm).
15+
To use this, you will need to create an etcd cluster and generate an apiserver-etcd-client certificate and private key. This behaviour can be tested using [`kubeadm`](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/setup-ha-etcd-with-kubeadm/) and [`etcdadm`](https://github.com/kubernetes-sigs/etcdadm).
1816

1917
### Setting up etcd with kubeadm
2018

21-
CA certificates are required to setup etcd cluster.
22-
If you already have a CA then the CA's `key` and `crt` must be copied to `/etc/kubernetes/pki/etcd/ca.crt` and `/etc/kubernetes/pki/etcd/ca.key`.
19+
CA certificates are required to setup etcd cluster. If you already have a CA then the CA's `crt` and `key` must be copied to `/etc/kubernetes/pki/etcd/ca.crt` and `/etc/kubernetes/pki/etcd/ca.key`.
2320

24-
If you do not already have a CA then run command `kubeadm init phase certs etcd-ca`. This creates two files
21+
If you do not already have a CA then run command `kubeadm init phase certs etcd-ca`. This creates two files:
2522

26-
* `/etc/kubernetes/pki/etcd/ca.crt`
27-
* `/etc/kubernetes/pki/etcd/ca.key`
23+
* `/etc/kubernetes/pki/etcd/ca.crt`
24+
* `/etc/kubernetes/pki/etcd/ca.key`
2825

29-
These key/pair are used to sign etcd server, peer certificates and eventually apiserver-etcd client. More information on how to setup external etcd with kubeadm can be found [`here`](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/setup-ha-etcd-with-kubeadm/#setting-up-the-cluster).
26+
This certificate and private key are used to sign etcd server, peer certificates and eventually apiserver-etcd-client certificate. More information on how to setup external etcd with kubeadm can be found [here](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/setup-ha-etcd-with-kubeadm/#setting-up-the-cluster).
3027

31-
You would require files `/etc/kubernetes/pki/apiserver-etcd-client.key`, `/etc/kubernetes/pki/apiserver-etcd-client.crt` and `/etc/kubernetes/pki/etcd/server.crt` to setup etcd cluster. These are put in 2 secrets.
28+
Once the etcd cluster is setup, you will need the following files from the etcd cluster:
3229

33-
```
34-
# Kubernetes APIServer etcd client certificate
30+
1. `/etc/kubernetes/pki/apiserver-etcd-client.crt` and `/etc/kubernetes/pki/apiserver-etcd-client.key`
31+
2. `/etc/kubernetes/pki/etcd/ca.crt`
32+
33+
You'll use these files to create the necessary Secrets on the management cluster (see the "Creating the required Secrets" section).
34+
35+
### Setting up etcd with etcdadm (Alpha)
36+
37+
`etcdadm` creates the CA if one does not exist, uses it to sign its server and peer certificates, and finally to sign the API server etcd client certificate. The CA's `crt` and `key` generated using `etcdadm` are stored in `/etc/etcd/pki/ca.crt` and `/etc/etcd/pki/ca.key`. `etcdadm` also generates a certificate for the API server etcd client; the certificate and private key are found at `/etc/etcd/pki/apiserver-etcd-client.crt` and `/etc/etcd/pki/apiserver-etcd-client.key`, respectively.
38+
39+
Once the etcd cluster has been bootstrapped using `etcdadm`, you will need the following files from the etcd cluster:
40+
41+
1. `/etc/etcd/pki/apiserver-etcd-client.crt` and `/etc/etcd/pki/apiserver-etcd-client.key`
42+
2. `/etc/etcd/pki/etcd/ca.crt`
43+
44+
You'll use these files in the next section to create the necessary Secrets on the management cluster.
45+
46+
## Creating the required Secrets
47+
48+
Regardless of the method used to bootstrap the etcd cluster, you will need to use the certificates copied from the etcd cluster to create some [Kubernetes Secrets](https://kubernetes.io/docs/concepts/configuration/secret/#creating-a-secret-using-kubectl-create-secret) on the management cluster.
49+
50+
In the commands below to create the Secrets, substitute `$CLUSTER_NAME` with the name of the workload cluster to be created by CAPI, and substitute `$CLUSTER_NAMESPACE` with the name of the namespace where the workload cluster will be created. The namespace can be omitted if the workload cluster will be created in the default namespace.
51+
52+
First, you will need to create a Secret containing the API server etcd client certificate and key. This command assumes the certificate and private key are in the current directory; adjust your command accordingly if they are not:
53+
54+
```bash
55+
# Kubernetes API server etcd client certificate and key
3556
$ kubectl create secret tls $CLUSTER_NAME-apiserver-etcd-client \
36-
--cert /etc/kubernetes/pki/apiserver-etcd-client.crt --key /etc/kubernetes/pki/apiserver-etcd-client.crt \
57+
--cert apiserver-etcd-client.crt \
58+
--key apiserver-etcd-client.key \
3759
--namespace $CLUSTER_NAMESPACE
60+
```
3861

62+
Next, create a Secret for the etcd cluster's CA certificate. The `kubectl create secret tls` command requires _both_ a certificate and a key, but the key isn't needed by CAPI. Instead, use the `kubectl create secret generic` command, and note that the file containing the CA certificate **must** be named `tls.crt`:
63+
64+
```bash
3965
# Etcd's CA crt file to validate the generated client certificates
40-
$ kubectl create secret tls $CLUSTER_NAME-etcd --cert /etc/kubernetes/pki/etcd/server.crt \
66+
$ kubectl create secret generic $CLUSTER_NAME-etcd \
67+
--from-file tls.crt \
4168
--namespace $CLUSTER_NAMESPACE
4269
```
43-
**Note:** Above command has key/pair base64 encoded by default.
4470

45-
**Note:** Alternatively you can base64 encode the files and put them in two secrets. The secrets
46-
must be formatted as follows and the cert material must be base64 encoded:
71+
**Note:** The above commands will base64 encode the certificate/key files by default.
72+
73+
Alternatively you can base64 encode the files and put them in two secrets. The secrets must be formatted as follows and the cert material must be base64 encoded:
4774

4875
```yaml
4976
# Kubernetes APIServer etcd client certificate
@@ -77,15 +104,11 @@ data:
77104
...
78105
```
79106
80-
### Setting up etcd with etcdadm (Alpha)
81-
`etcdadm` creates the CA if one does not exist, uses it to sign it's server and peer certificates, and finally to sign the apiserver etcd client certificate.
82-
CA's `key` and `crt` generated using `etcdadm` are stored in `/etc/etcd/pki/apiserver-etcd-client.crt`, `/etc/etcd/pki/apiserver-etcd-client.key` and `/etc/etcd/pki/server.crt` .
83-
84-
85-
Just like kubeadm, it is required to create 2 [`secrets`](https://kubernetes.io/docs/concepts/configuration/secret/#creating-a-secret-using-kubectl-create-secret) using these server and etcd client key/pair.
107+
The Secrets must be created _before_ creating the workload cluster.
86108
87109
## Configuring CABPK
88-
After that the rest is standard Kubeadm. Config your ClusterConfiguration as follows:
110+
111+
Once the Secrets are in place on the management cluster, the rest of the process leverages standard `kubeadm` configuration. Configure your ClusterConfiguration for the workload cluster as follows:
89112

90113
```yaml
91114
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
@@ -106,4 +129,8 @@ spec:
106129
... # other clusterConfiguration goes here
107130
```
108131

109-
Create your cluster as normal!
132+
Create your workload cluster as normal. The new workload cluster should use the configured external etcd nodes instead of creating co-located etcd Pods on the control plane nodes.
133+
134+
## Additional Notes/Caveats
135+
136+
* Depending on the provider, additional changes to the workload cluster's manifest may be necessary to ensure the new CAPI-managed nodes have connectivity to the existing etcd nodes. For example, on AWS you will need to leverage the `additionalSecurityGroups` field on the AWSMachine and/or AWSMachineTemplate objects to add the CAPI-managed nodes to a security group that has connectivity to the existing etcd cluster. Other mechanisms exist for other providers.

0 commit comments

Comments
 (0)