cat > /etc/ssl/kubectl/admin-csr.json <<EOF
{
"CN": "admin",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "ChengDu",
"L": "ChengDu",
"O": "system:masters",
"OU": "dessler"
}
]
}
EOF
複製代碼
cfssl gencert -ca=/etc/ssl/ca.pem \
-ca-key=/etc/ssl/ca-key.pem \
-config=//etc/ssl/ca-config.json \
-profile=kubernetes admin-csr.json | cfssljson -bare admin
複製代碼
ls
admin.csr admin-csr.json admin-key.pem admin.pem
複製代碼
kubectl config set-cluster kubernetes \
> --certificate-authority=/etc/ssl/ca.pem \
> --embed-certs=true \
> --server=https://192.168.1.43:8443 \
> --kubeconfig=kubectl.kubeconfig
Cluster "kubernetes" set.
複製代碼
kubectl config set-credentials admin \
> --client-certificate=/etc/ssl/kubectl/admin.pem \
> --client-key=/etc/ssl/kubectl/admin-key.pem \
> --embed-certs=true \
> --kubeconfig=kubectl.kubeconfig
User "admin" set.
複製代碼
kubectl config set-context kubernetes \
> --cluster=kubernetes \
> --user=admin \
> --kubeconfig=kubectl.kubeconfig
Context "kubernetes" created.
複製代碼
kubectl config use-context kubernetes --kubeconfig=kubectl.kubeconfig
Switched to context "kubernetes".
複製代碼
其餘服務若是須要使用kubectl命令,只要有二進制文件和這個配置文件,就能夠直接鏈接kubernetes集羣json