在开始安装 Kubernetes 之前,需要先将一些必要系统创建完成,其中 Etcd 就是 Kubernetes 最重要的一环,Kubernetes 会将大部分信息储存于 Etcd 上,来提供给其他节点索取,以确保整个集群运作与沟通正常。
    创建集群 CA 与 Certificates

    在这部分,将会需要产生 client 与 server 的各组件 certificates,并且替 Kubernetes admin user 产生 client 证书。
    建立/etc/etcd/ssl文件夹,然后进入目录完成以下操作。

    1. wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
    2. wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
    3. wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
    4. chmod +x cfssl*

    将这三个二进制可执行文件,修改名称复制到/usr/local/bin/下

    1. [root@localhost ~]# ll /usr/local/bin/
    2. 总用量 18808
    3. -rwxr-xr-x. 1 root root 10376657 3 30 2016 cfssl
    4. -rwxr-xr-x. 1 root root 6595195 3 30 2016 cfssl-certinfo
    5. -rwxr-xr-x. 1 root root 2277873 3 30 2016 cfssljson

    使用CFSSL创建CA证书以及etcd的TLS认证证书
    创建 CA (Certificate Authority)
    创建 CA 配置文件(ca-config.json)

    1. [root@localhost ssl]# cat ca-config.json
    2. {
    3. "signing": {
    4. "default": {
    5. "expiry": "87600h"
    6. },
    7. "profiles": {
    8. "etcd": {
    9. "expiry": "87600h",
    10. "usages": [
    11. "signing",
    12. "key encipherment",
    13. "server auth",
    14. "client auth"
    15. ]
    16. },
    17. "expiry": "87600h"
    18. }
    19. }
    20. }
    21. }
    22. [root@localhost ssl]#

    “字段说明” “ca-config.json”:可以定义多个 profiles,分别指定不同的过期时间、使用场景等参数;后续在签名证书时使用某个 profile; “signing”:表示该证书可用于签名其它证书;生成的 ca.pem 证书中 CA=TRUE; “server auth”:表示client可以用该 CA 对server提供的证书进行验证; “client auth”:表示server可以用该CA对client提供的证书进行验证;

    创建 CA 证书签名请求(ca-csr.json)

    1. [root@localhost ssl]# cat ca-csr.json
    2. {
    3. "CN": "etcd",
    4. "key": {
    5. "algo": "rsa",
    6. "size": 2048
    7. },
    8. "names": [
    9. {
    10. "C": "CN",
    11. "ST": "wuhan",
    12. "L": "wuhan",
    13. "O": "etcd",
    14. "ST": "System"
    15. }
    16. ]
    17. }

    “CN”:Common Name,etcd 从证书中提取该字段作为请求的用户名 (User Name);浏览器使用该字段验证网站是否合法; “O”:Organization,etcd 从证书中提取该字段作为请求用户所属的组 (Group); 这两个参数在后面的kubernetes启用RBAC模式中很重要,因为需要设置kubelet、admin等角色权限,那么在配置证书的时候就必须配置对了,具体后面在部署kubernetes的时候会进行讲解。 “在etcd这两个参数没太大的重要意义,跟着配置就好。”

    生成 CA 证书和私钥

    1. [root@localhost ssl]# cfssl gencert -initca ca-csr.json|cfssljson -bare ca
    2. 2019/08/29 18:43:38 [INFO] generating a new CA key and certificate from CSR
    3. 2019/08/29 18:43:38 [INFO] generate received request
    4. 2019/08/29 18:43:38 [INFO] received CSR
    5. 2019/08/29 18:43:38 [INFO] generating key: rsa-2048
    6. 2019/08/29 18:43:38 [INFO] encoded CSR
    7. 2019/08/29 18:43:38 [INFO] signed certificate with serial number 25156972509303128085601524248922010370512108985
    8. [root@localhost ssl]# ll
    9. 总用量 28
    10. -rw-r--r--. 1 root root 427 8 29 18:34 ca-config.json
    11. -rw-r--r--. 1 root root 968 8 29 18:43 ca.csr
    12. -rw-r--r--. 1 root root 256 8 29 18:41 ca-csr.json
    13. -rw-------. 1 root root 1679 8 29 18:43 ca-key.pem
    14. -rw-r--r--. 1 root root 1289 8 29 18:43 ca.pem
    15. -rw-r--r--. 1 root root 567 8 29 18:20 config.json
    16. -rw-r--r--. 1 root root 287 8 29 18:23 csr.json
    17. [root@localhost ssl]#