k8s部署---node节点组件部署

Posted

tags:

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

kubelet组件简介
  • kubernetes 是一个分布式的集群管理系统,在每个节点(node)上都要运行一个 worker 对容器进行生命周期的管理,这个 worker 程序就是 kubelet
  • kubelet 的主要功能就是定时从某个地方获取节点上 pod/container 的期望状态(运行什么容器、运行的副本数量、网络或者存储如何配置等等),并调用对应的容器平台接口达到这个状态。

kubelet组件特性

  • 定时汇报当前节点的状态给 apiserver,以供调度的时候使用
  • 镜像和容器的清理工作,保证节点上镜像不会占满磁盘空间,退出的容器不会占用太多资源
  • 运行 HTTP Server,对外提供节点和 pod 信息,如果在 debug 模式下,还包括调试信息
  • 等等...

kubelet 主要功能

  • Pod 管理
  • 容器健康检查
  • 容器监控

kube-proxy组件介绍

  • 在 node节点上实现 Pod网络代理,维护网络规划和四层负载均衡工作

实验部署

实验环境

  • Master01:192.168.80.12
  • Node01:192.168.80.13
  • Node02:192.168.80.14
  • 本篇实验部署是接上篇文章master节点部署继续部署,实验环境不变,本篇文章主要是部署node节点中kubelet组件与kube-proxy组件

kubelet组件部署

  • master01服务器操作
    [root@master01 k8s]# cd /root/k8s/kubernetes/server/bin     //进入之前解压好的软件命令目录
    [root@master01 bin]# ls
    apiextensions-apiserver              kube-apiserver.docker_tag           kube-proxy
    cloud-controller-manager             kube-apiserver.tar                  kube-proxy.docker_tag
    cloud-controller-manager.docker_tag  kube-controller-manager             kube-proxy.tar
    cloud-controller-manager.tar         kube-controller-manager.docker_tag  kube-scheduler
    hyperkube                            kube-controller-manager.tar         kube-scheduler.docker_tag
    kubeadm                              kubectl                             kube-scheduler.tar
    kube-apiserver                       kubelet                             mounter
    [root@master01 bin]# scp kubelet kube-proxy root@192.168.80.13:/opt/kubernetes/bin/   //把 kubelet、 kube-proxy拷贝到node节点上去
    root@192.168.80.13‘s password:
    kubelet                                                                    100%  168MB  91.4MB/s   00:01
    kube-proxy                                                                 100%   48MB  71.8MB/s   00:00
    [root@master01 bin]# scp kubelet kube-proxy root@192.168.80.14:/opt/kubernetes/bin/
    root@192.168.80.14‘s password:
    kubelet                                                                    100%  168MB 122.5MB/s   00:01
    kube-proxy                                                                 100%   48MB  95.2MB/s   00:00
    [root@master01 bin]# scp /mnt/node.zip root@192.168.80.13:/root     //将宿主机挂载的压缩文件拷贝到node01节点
    root@192.168.80.13‘s password:
    node.zip                                                                   100% 1240     4.1KB/s     00:00
  • node01节点操作
    [root@node01 ~]# ls
    anaconda-ks.cfg  flannel.sh  flannel-v0.10.0-linux-amd64.tar.gz  node.zip  README.md
    [root@node01 ~]# unzip node.zip        //解压压缩包
    Archive:  node.zip
    inflating: proxy.sh
    inflating: kubelet.sh
  • master01节点操作

    [root@master01 bin]# cd /root/k8s/
    [root@master01 k8s]# mkdir kubeconfig          //创建配置文件目录
    [root@master01 k8s]# cd kubeconfig
    [root@master01 kubeconfig]# cp /mnt/kubeconfig.sh /root/k8s/kubeconfig/      //拷贝脚本到配置文件目录
    [root@master01 kubeconfig]# mv kubeconfig.sh kubeconfig                  //更名
    [root@master01 kubeconfig]# vim kubeconfig              //编辑文件
    # 创建 TLS Bootstrapping Token
    #BOOTSTRAP_TOKEN=$(head -c 16 /dev/urandom | od -An -t x | tr -d ‘ ‘)
    BOOTSTRAP_TOKEN=0fb61c46f8991b718eb38d27b605b008
    
    cat > token.csv <<EOF
    ${BOOTSTRAP_TOKEN},kubelet-bootstrap,10001,"system:kubelet-bootstrap"
    EOF
    //删除此部分内容
    ...
    :wq
    [root@master01 kubeconfig]# cat /opt/kubernetes/cfg/token.csv        //查看token文件获取序列号即可
    c37758077defd4033bfe95a071689272,kubelet-bootstrap,10001,"system:kubelet-bootstrap"
    [root@master01 kubeconfig]# vim kubeconfig
    ...
    # 设置客户端认证参数
    kubectl config set-credentials kubelet-bootstrap --token=c37758077defd4033bfe95a071689272             //修改为tokenID 将变量更改为获取的序列号
    --kubeconfig=bootstrap.kubeconfig
    ...
    :wq
    [root@master01 kubeconfig]# vim /etc/profile               //编辑文件设置环境变量
    ...
    export PATH=$PATH:/opt/kubernetes/bin/
    :wq
    [root@master01 kubeconfig]# source /etc/profile           //重新执行文件
    [root@master01 kubeconfig]# kubectl get cs               //查看群集状态,确认群集正常
    NAME                 STATUS    MESSAGE             ERROR
    scheduler            Healthy   ok
    controller-manager   Healthy   ok
    etcd-0               Healthy   {"health":"true"}
    etcd-1               Healthy   {"health":"true"}
    etcd-2               Healthy   {"health":"true"}
    [root@master01 kubeconfig]# bash kubeconfig 192.168.80.12 /root/k8s/k8s-cert/   //使用命令生成配置文件
    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".
    [root@master01 kubeconfig]# ls
    bootstrap.kubeconfig  kubeconfig  kube-proxy.kubeconfig         //生成两个配置文件
    [root@master01 kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.80.13:/opt/kubernetes/cfg/                //将生成的配置文件拷贝到node节点中
    root@192.168.80.13‘s password:
    bootstrap.kubeconfig                                                       100% 2167     1.1MB/s   00:00
    kube-proxy.kubeconfig                                                      100% 6269     7.1MB/s   00:00
    [root@master01 kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.80.14:/opt/kubernetes/cfg/
    root@192.168.80.14‘s password:
    bootstrap.kubeconfig                                                       100% 2167     1.6MB/s   00:00
    kube-proxy.kubeconfig                                                      100% 6269     4.5MB/s   00:00
    [root@master01 kubeconfig]# kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap     //创建bootstrap角色赋予权限用于连接apiserver请求签名(关键点)
    clusterrolebinding.rbac.authorization.k8s.io/kubelet-bootstrap created
  • node01节点操作
    [root@node01 ~]# ls /opt/kubernetes/cfg/         //检查是否成功拷贝
    bootstrap.kubeconfig  flanneld  kube-proxy.kubeconfig
    [root@node01 ~]# bash kubelet.sh 192.168.80.13           //执行脚本文件生成kubelet的配置文件与启动脚本
    Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
    [root@node01 ~]# systemctl status kubelet.service         //查看服务是否启动
    ● kubelet.service - Kubernetes Kubelet
    Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
    Active: active (running) since 一 2020-02-10 14:17:12 CST; 1min 45s ago      //成功运行
    Main PID: 79678 (kubelet)
    Memory: 14.2M
    ...
  • master01服务器操作
    [root@master01 kubeconfig]# kubectl get csr              //查看是否有node01节点请求申请证书
    NAME                                                   AGE     REQUESTOR           CONDITION
    node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w   3m16s   kubelet-bootstrap   Pending
    [root@master01 kubeconfig]# kubectl certificate approve  node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w            //同意自签node01节点自签请求
    certificatesigningrequest.certificates.k8s.io/node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w approved
    [root@master01 kubeconfig]# kubectl get csr          //同意后再次查看请求状态
    NAME                                                   AGE     REQUESTOR           CONDITION
    node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w   4m40s   kubelet-bootstrap   Approved,Issued   //已经被允许加入群集
    [root@master01 kubeconfig]# kubectl get node      //查看群集节点,成功加入node01节点
    NAME            STATUS   ROLES    AGE   VERSION
    192.168.80.13   Ready    <none>   78s   v1.12.3
  • node01节点操作
    [root@node01 ~]# bash proxy.sh 192.168.80.13     //执行脚本文件,启动kube-proxy服务并生成配置文件
    Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/ systemd/system/kube-proxy.service.
    [root@node01 ~]# systemctl status kube-proxy.service     //查看服务是否启动
    ● kube-proxy.service - Kubernetes Proxy
    Loaded: loaded (/usr/lib/systemd/system/kube-proxy.service; enabled; vendor preset: disabled)
    Active: active (running) since 一 2020-02-10 14:23:59 CST; 1min 2s ago   //成功启动
    Main PID: 80889 (kube-proxy)
    ...
    [root@node01 ~]# scp -r /opt/kubernetes/ root@192.168.80.14:/opt/    //把现成的/opt/kubernetes目录复制到node02节点进行修改即可
    The authenticity of host ‘192.168.80.14 (192.168.80.14)‘ can‘t be established.
    ECDSA key fingerprint is SHA256:Ih0NpZxfLb+MOEFW8B+ZsQ5R8Il2Sx8dlNov632cFlo.
    ECDSA key fingerprint is MD5:a9:ee:e5:cc:40:c7:9e:24:5b:c1:cd:c1:7b:31:42:0f.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added ‘192.168.80.14‘ (ECDSA) to the list of known hosts.
    root@192.168.80.14‘s password:
    flanneld                                                                   100%  235   139.5KB/s   00:00
    bootstrap.kubeconfig                                                       100% 2167     4.6MB/s   00:00
    kube-proxy.kubeconfig                                                      100% 6269    14.2MB/s   00:00
    kubelet                                                                    100%  377   430.7KB/s   00:00
    kubelet.config                                                             100%  267   262.3KB/s   00:00
    kubelet.kubeconfig                                                         100% 2296     3.3MB/s   00:00
    kube-proxy                                                                 100%  189   299.2KB/s   00:00
    mk-docker-opts.sh                                                          100% 2139     2.3MB/s   00:00
    scp: /opt//kubernetes/bin/flanneld: Text file busy
    kubelet                                                                    100%  168MB 134.1MB/s   00:01
    kube-proxy                                                                 100%   48MB 129.8MB/s   00:00
    kubelet.crt                                                                100% 2185     3.3MB/s   00:00
    kubelet.key                                                                100% 1675     2.8MB/s   00:00
    kubelet-client-2020-02-10-14-21-18.pem                                     100% 1273   608.4KB/s   00:00
    kubelet-client-current.pem                                                 100% 1273   404.9KB/s   00:00
    [root@node01 ~]# scp /usr/lib/systemd/system/{kubelet,kube-proxy}.service root@192.168.80.14:/usr/lib/systemd/system/          //把kubelet,kube-proxy的service文件拷贝到node2中
    root@192.168.80.14‘s password:
    kubelet.service                                                            100%  264   350.1KB/s   00:00
    kube-proxy.service                                                         100%  231   341.5KB/s    00:00
  • node02上操作
    [root@node02 ~]# cd /opt/kubernetes/ssl/    //进入node01节点拷贝过来的证书目录
    [root@node02 ssl]# rm -rf *               //删除证书,稍后我们在重新申请证书
    [root@node02 ssl]# cd ../cfg/              //进入配置文件目录
    [root@node02 cfg]# vim kubelet            //修改文件
    KUBELET_OPTS="--logtostderr=true --v=4 --hostname-override=192.168.80.14         //修改IP地址
    --kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig --bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig --config=/opt/kubernetes/cfg/kubelet.config --cert-dir=/opt/kubernetes/ssl --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
    :wq
    [root@node02 cfg]# vim kubelet.config      //修改配置文件
    kind: KubeletConfiguration
    apiVersion: kubelet.config.k8s.io/v1beta1
    address: 192.168.80.14                       //修改IP地址
    port: 10250
    readOnlyPort: 10255
    cgroupDriver: cgroupfs
    clusterDNS:
    - 10.0.0.2
    clusterDomain: cluster.local.
    failSwapOn: false
    authentication:
    anonymous:
    enabled: true
    :wq
    [root@node02 cfg]# vim kube-proxy       //修改kube-proxy配置文件
    KUBE_PROXY_OPTS="--logtostderr=true --v=4 --hostname-override=192.168.80.14       //修改IP地址
    --cluster-cidr=10.0.0.0/24 --proxy-mode=ipvs --kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"
    :wq
    [root@node02 cfg]# systemctl start kubelet.service       //启动服务
    [root@node02 cfg]# systemctl enable kubelet.service      //设置开机自启
    Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
    [root@node02 cfg]# systemctl start kube-proxy.service     //启动服务
    [root@node02 cfg]# systemctl enable kube-proxy.service    //设置开机自启
    Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/ systemd/system/kube-proxy.service.
  • master01节点操作
    [root@master01 kubeconfig]# kubectl get csr       //查看node节点请求
    NAME                                                   AGE     REQUESTOR           CONDITION
    node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w   22m     kubelet-bootstrap   Approved,Issued
    node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0   4m54s   kubelet-bootstrap   Pending    //等待集群给该节点颁发证书
    [root@master01 kubeconfig]# kubectl certificate approve node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0       //使用命令授权许可加入群集
    certificatesigningrequest.certificates.k8s.io/node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 approved
    [root@master01 kubeconfig]# kubectl get csr    //再次查看node节点请求
    NAME                                                   AGE     REQUESTOR           CONDITION
    node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w   23m     kubelet-bootstrap   Approved,Issued
    node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0   5m58s   kubelet-bootstrap   Approved,Issued   //成功加入
    [root@master01 kubeconfig]# kubectl get node    //查看群集中的节点
    NAME            STATUS   ROLES    AGE   VERSION
    192.168.80.13   Ready    <none>   20m   v1.12.3
    192.168.80.14   Ready    <none>   76s   v1.12.3   //成功加入节点

    node节点部署完成

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

k8s单节点集群二进制部署(步骤详细,图文详解)

k8s单节点集群二进制部署(步骤详细,图文详解)

k8s单节点集群二进制部署(步骤详细,图文详解)

K8S—二进制部署安装

K8S—二进制部署安装(包含UI界面设置)

K8S—二进制部署安装(包含UI界面设置)