Loading

手动制作CA证书

一、安装 CFSSL

 证书下载官方地址:https://pkg.cfssl.org

#下面三个安装包,无需下载,之前百度云中的压缩包中都有
[root@linux-node1 ~]# cd /usr/local/src [root@linux-node1 src]# wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 [root@linux-node1 src]# wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 [root@linux-node1 src]# wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 [root@linux-node1 src]# chmod +x cfssl* [root@linux-node1 src]# mv cfssl-certinfo_linux-amd64 /opt/kubernetes/bin/cfssl-certinfo [root@linux-node1 src]# mv cfssljson_linux-amd64 /opt/kubernetes/bin/cfssljson [root@linux-node1 src]# mv cfssl_linux-amd64 /opt/kubernetes/bin/cfssl 复制cfssl命令文件到k8s-node1和k8s-node2节点。如果实际中多个节点,就都需要同步复制。 [root@linux-node1 ~]# scp /opt/kubernetes/bin/cfssl* 192.168.56.12: /opt/kubernetes/bin [root@linux-node1 ~]# scp /opt/kubernetes/bin/cfssl* 192.168.56.13: /opt/kubernetes/bin

二、创建生成证书临时存放目录

[root@linux-node1 ~]# cd /usr/local/src/
[root@linux-node1 src]# mkdir ssl && cd ssl
[root@linux-node1 ssl]# pwd
/usr/local/src/ssl

三、创建用来生成CA文件的JSON配置文件

[root@linux-node1 ssl]# vim ca-config.json
{
  "signing": {
    "default": {
      "expiry": "8760h"
    },
    "profiles": {
      "kubernetes": {
        "usages": [
            "signing",
            "key encipherment",
            "server auth",
            "client auth"
        ],
        "expiry": "8760h"
      }
    }
  }
}

四、创建用来生成CA证书请求(CSR)的JSON配置文件

[root@linux-node1 ssl]# vim ca-csr.json
{
  "CN": "kubernetes",
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}

五、生成CA证书(ca.pem)和密钥(ca-key.pem)

[root@linux-node1 ssl]# cfssl gencert -initca ca-csr.json | cfssljson -bare ca
2018/05/30 20:57:27 [INFO] generating a new CA key and certificate from CSR
2018/05/30 20:57:27 [INFO] generate received request
2018/05/30 20:57:27 [INFO] received CSR
2018/05/30 20:57:27 [INFO] generating key: rsa-2048
2018/05/30 20:57:27 [INFO] encoded CSR
2018/05/30 20:57:27 [INFO] signed certificate with serial number 373140524131197437929619452877769287318483665014
[root@linux-node1 ssl]# ls -l
total 20
-rw-r--r-- 1 root root  290 May 30 20:55 ca-config.json
-rw-r--r-- 1 root root 1001 May 30 20:57 ca.csr
-rw-r--r-- 1 root root  208 May 30 20:56 ca-csr.json
-rw------- 1 root root 1675 May 30 20:57 ca-key.pem

六、分发证书

[root@linux-node1 ssl]# cp ca.csr ca.pem ca-key.pem ca-config.json /opt/kubernetes/ssl
SCP证书到k8s-node1和k8s-node2节点
[root@linux-node1 ssl]# scp ca.csr ca.pem ca-key.pem ca-config.json 192.168.56.12:/opt/kubernetes/ssl
[root@linux-node1 ssl]# scp ca.csr ca.pem ca-key.pem ca-config.json 192.168.56.13:/opt/kubernetes/ssl

 

 

 

 

 

 

 

 

 
posted @ 2018-05-29 19:28  KubeSec  阅读(1856)  评论(0编辑  收藏  举报