k8s-创建node节点kubeconfig配置文件

Posted shanhua-fu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s-创建node节点kubeconfig配置文件相关的知识,希望对你有一定的参考价值。

技术图片

Kubeconfig 需要配置如下

  1. TLS Bootstrapping Token
  2. kubelet kubeconfig
  3. 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

 

[[email protected] src]# chmod +x kubectl
[[email protected] src]# mv kubectl /opt/kubernetes/bin/

[[email protected] src]# vi /etc/profile

export KUBERNETES_HOME=/opt/kubernetes
export PATH=$KUBERNETES_HOME/bin:$PATH

[[email protected] 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

 

[[email protected] src]# chmod +x kubeconfig.sh
[[email protected] src]# mv kubeconfig.sh /opt/kubernetes/ssl/
[[email protected] src]# cd /opt/kubernetes/ssl/
[[email protected] 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地址

[[email protected] 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".

以上是关于k8s-创建node节点kubeconfig配置文件的主要内容,如果未能解决你的问题,请参考以下文章

k8s-高可用配置

K8S 核心组件 kubelet 与 kube-proxy 分析

Kubernetes多master部署---创建Node节点kubeconfig文件

扩容node节点

K8s手工创建kubeconfig

6、二进制安装K8s之部署kubectl