赞
踩
vim ca-config.json
{ "signing": { "default": { "expiry": "87600h" }, "profiles": { "etcd": { "expiry": "87600h", "usages": [ "signing", "key encipherment", "server auth", "client auth" ] } } } }
“CN”:Common Name,从证书中提取该字段作为请求的用户名 (User Name);浏览器使用该字段验证网站是否合法;
“O”:Organization,从证书中提取该字段作为请求用户所属的组 (Group);
这两个参数在后面的kubernetes启用RBAC模式中很重要,因为需要设置kubelet、admin等角色权限,那么在配置证书的时候就必须配置对了,具体后面在部署kubernetes的时候会进行讲解。
“在etcd这两个参数没太大的重要意义,跟着配置就好。”
创建配置文件
vim ca-csr.json
{
"CN": "etcd CA",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "shanghai",
"ST": "shanghai"
}
]
}
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
ls
ca-config.json ca-csr.json ca.csr ca.pem(ca公钥) ca-key.pem(ca私钥,妥善保管)
vim server-csr.json
{ "CN": "etcd", "key": { "algo": "rsa", "size": 2048 }, "hosts": [ "192.168.1.221", "192.168.1.222", "192.168.1.223" ], "names": [ { "C": "CN", "L": "shanghai", "ST": "shanghai" } ] }
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=etcd server-csr.json | cfssljson -bare server
ls
ca-config.json ca-csr.json ca-key.pem ca.csr ca.pem server-csr.json server-key.pem server.csr server.pem
将证书放到其他节点的同个位置上。
编辑各节点上的配置文件
vim /etc/etcd/etcd.conf
加入TLS证书的配置
# [Security]
ETCD\_TRUSTED\_CA\_FILE="/opt/cfssl/ca.pem"
ETCD\_CERT\_FILE="/opt/cfssl/server.pem"
ETCD\_KEY\_FILE="/opt/cfssl/server-key.pem"
ETCD\_PEER\_TRUSTED\_CA\_FILE="/opt/cfssl/ca.pem"
ETCD\_PEER\