二进制安装K8S(五):创建node节点kubeconfig文件
一、在master节点上编写生成kubeconfig文件脚本:vim /root/scripts/kubeconfig.sh#!/bin/bash#下载kubectl命令version=curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txtwgethttps://storage.goog...
一、在master节点上编写生成kubeconfig文件脚本:
vim /root/scripts/kubeconfig.sh
#!/bin/bash
#下载kubectl命令
version=curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt
wget https://storage.googleapis.com/kubernetes-release/release/${version}/bin/linux/amd64/kubectl
mv kubectl /opt/kubernetes/bin/
chmod 755 /opt/kubernetes/bin/kubectl
rm -rf /usr/local/bin/kubectl
ln -s /opt/kubernetes/bin/kubectl /usr/local/bin/
#创建TLS Bootstrapping Token
export BOOTSTRAP_TOKEN=$(head -c 16 /dev/urandom | od -An -t x | tr -d ’ ')
cat > /opt/kubernetes/cfg/token.csv <<EOF
${BOOTSTRAP_TOKEN},kubelet-bootstrap,10001,“system:kubelet-bootstrap”
EOF
#创建kubelet bootstrapping kubeconfig
export KUBE_APISERVER=“https://192.168.1.250:6443”
#设置集群参数
cd /opt/kubernetes/ssl/
kubectl config set-cluster kubernetes
–certificate-authority=ca.pem
–embed-certs=true
–server=${KUBE_APISERVER}
–kubeconfig=bootstrap.kubeconfig
#设置客户端认证参数
kubectl config set-credentials kubelet-bootstrap
–token=${BOOTSTRAP_TOKEN}
–kubeconfig=bootstrap.kubeconfig
#设置上下文参数
kubectl config set-context default
–cluster=kubernetes
–user=kubelet-bootstrap
–kubeconfig=bootstrap.kubeconfig
#设置默认上下文
kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
#创建kube-proxy kubeconfig文件:(步骤和上面类似)
kubectl config set-cluster kubernetes
–certificate-authority=ca.pem
–embed-certs=true
–server=${KUBE_APISERVER}
–kubeconfig=kube-proxy.kubeconfig
kubectl config set-credentials kube-proxy
–client-certificate=kube-proxy.pem
–client-key=kube-proxy.pem
–embed-certs=true
–kubeconfig=kube-proxy.kubeconfig
kubectl config set-context default
–cluster=kubernetes
–user=kube-proxy
–kubeconfig=kube-proxy.kubeconfig
kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
#将刚才生成的kubeconfig配置文件从master节点拷贝到node节点上
cd /opt/kubernetes/ssl
scp *.kubeconfig 192.168.1.75:/opt/kubernetes/cfg/
scp *.kubeconfig 192.168.1.76:/opt/kubernetes/cfg/
scp *.kubeconfig 192.168.1.77:/opt/kubernetes/cfg/
二、执行脚本:
sh /root/scripts/kubeconfig.sh
更多推荐
所有评论(0)