k8s 1.9.8 安装(2)cfssl生成证书

返回总目录连接

文章目录

    • 0.证书的选择
    • 1下载、安装
    • 2 CA 证书和私钥
    • 3 kubernetes 证书
    • 4创建 admin 证书
    • 5 kube-proxy证书
    • 6将密钥拷贝到/etc/kubernets/ssl发送到node1、node2

0.证书的选择

1.第三方机构颁发,有的需要花钱购买,也有免费的,一般用于互联网访问网站
2.自发证书 一般使用与内部网络
cfssl 简单
openssl

1下载、安装

cd /usr/local/src
wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64

chmod +x cfssl*
mv cfssl_linux-amd64 /usr/local/bin/cfssl
mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
mv cfssl-certinfo_linux-amd64 /usr/local/bin/cfssl-certinfo

export PATH=/usr/local/bin:$PATH

2 CA 证书和私钥

mkdir ssl && cd ssl && vim  ca-config.json

{
  "signing": {
    "default": {
      "expiry": "87600h"
    },
    "profiles": {
      "kubernetes": {
        "usages": [
            "signing",
            "key encipherment",
            "server auth",
            "client auth"
        ],
        "expiry": "87600h"
      }
    }
  }
}

vim  ca-csr.json

{
  "CN": "kubernetes",
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ],
    "ca": {
       "expiry": "87600h"
    }
}

cfssl gencert -initca ca-csr.json | cfssljson -bare ca

3 kubernetes 证书

vim kubernetes-csr.json
{
   "CN": "kubernetes",
    "hosts": [
      "127.0.0.1",
      "192.168.1.25",
      "192.168.1.26",
      "192.168.1.27",
      "master",
      "node1",
      "node2",
      "kubernetes",
      "kubernetes.default",
      "kubernetes.default.svc",
      "kubernetes.default.svc.cluster",
      "kubernetes.default.svc.cluster.local",
      "10.254.0.1"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "ST": "BeiJing",
            "L": "BeiJing",
            "O": "k8s",
            "OU": "System"
        }
    ]
}

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes kubernetes-csr.json | cfssljson -bare kubernetes

4创建 admin 证书

vim admin-csr.json
{
  "CN": "admin",
  "hosts": [],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "system:masters",
      "OU": "System"
    }
  ]
}

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes admin-csr.json | cfssljson -bare admin

5 kube-proxy证书

vim kube-proxy-csr.json
{
  "CN": "system:kube-proxy",
  "hosts": [],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes  kube-proxy-csr.json | cfssljson -bare kube-proxy

6将密钥拷贝到/etc/kubernets/ssl发送到node1、node2

cp *  /etc/kubernetes/ssl/
scp  *.pem root@node1:/etc/kubernetes/ssl/
scp  *.pem root@node2:/etc/kubernetes/ssl/

你可能感兴趣的:(k8s)