Kubeconfig 需要配置如下
- TLS Bootstrapping Token
- kubelet kubeconfig
- kube-proxy kubeconfig
下载kubectl kubectl下载地址:https://kubernetes.io/docs/tasks/tools/install-kubectl/ 我测试选择的是安装kubectl二进制文件 linux最新版本下载地址:curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl 也可以指定版本,比如我测试使用的1.9.0 curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl
[root@k8s-master src]# chmod +x kubectl
[root@k8s-master src]# mv kubectl /opt/kubernetes/bin/
[root@k8s-master src]# vi /etc/profile
export KUBERNETES_HOME=/opt/kubernetes
export PATH=$KUBERNETES_HOME/bin:$PATH
[root@k8s-master src]# source /etc/profile
kubeconfig配置文件创建,直接用下面kubeconfig.sh脚本文件生成 注意:export KUBE_APISERVER设置master的ip
# 创建 TLS Bootstrapping Token export BOOTSTRAP_TOKEN=$(head -c 16 /dev/urandom | od -An -t x | tr -d ' ') cat > token.csv <<EOF ${BOOTSTRAP_TOKEN},kubelet-bootstrap,10001,"system:kubelet-bootstrap" EOF #---------------------- # 创建kubelet bootstrapping kubeconfig export KUBE_APISERVER="https://192.168.10.60:6443" # 设置集群参数 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-key.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
[root@k8s-master src]# chmod +x kubeconfig.sh
[root@k8s-master src]# mv kubeconfig.sh /opt/kubernetes/ssl/
[root@k8s-master src]# cd /opt/kubernetes/ssl/
[root@k8s-master ssl]# ./kubeconfig.sh
Cluster "kubernetes" set.
User "kubelet-bootstrap" set.
Context "default" created.
Switched to context "default".
Cluster "kubernetes" set.
User "kube-proxy" set.
Context "default" created.
Switched to context "default".
####由于没有修改apiserver地址
[root@k8s-master ssl]# ./kubeconfig.sh
Cluster "kubernetes" set.
User "kubelet-bootstrap" set.
Context "default" modified.
Switched to context "default".
Cluster "kubernetes" set.
User "kube-proxy" set.
Context "default" modified.
Switched to context "default".