复制 DOWNURL='https://storage.googleapis.com/kubernetes-release/release'
#获取最新版本的kubrnetes
GETVERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
#下载kubectl
curl -L ${DOWNURL}/${GETVERSION}/bin/linux/amd64/kube-apiserver -o /srv/kubernetes/bin/kubectl
cd /srv/kubernetes/bin
chmod +x kubectl
复制 cat > admin-csr.json <<EOF
{
"CN": "admin",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "BeiJing",
"O": "system:masters",
"OU": "gxd-test",
"ST": "BeiJing"
}
]
}
EOF
复制 cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
-profile=kubernetes \
admin-csr.json | cfssljson -bare admin
复制 export KUBE_APISERVER="https://apiserver-p001.svc.gxd88.cn:6443"
复制 kubectl config set-cluster kubernetes \
--certificate-authority=ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER}
复制 kubectl config set-credentials admin \
--client-certificate=admin.pem \
--embed-certs=true \
--client-key=admin-key.pem
复制 kubectl config set-context kubernetes \
--cluster=kubernetes \
--user=admin
复制 kubectl config use-context kubernetes
复制 yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc