• Centos7 k8s v1.5.2二进制部署安装-kubelet组件安装


    一、部署kubectl服务

      1、工作流程图

             

      2、Kubelet组件运行在Node节点上,维持运行中的Pods以及提供kuberntes运行时环境,主要完成以下使命: 

        1)监视分配给该Node节点的pods 
        2)挂载pod所需要的volumes 
        3)下载pod的secret 
        4)通过docker/rkt来运行pod中的容器 
        5)周期的执行pod中为容器定义的liveness探针 
        6)上报pod的状态给系统的其他组件 
        7)上报Node的状态

      kubelet安装在node节点,我们的node跟apiserver在一起,这里安装在hdss7-21,22上:

      首先,kubernetes依赖pause,我们先将此服务上传到们自己的docker私有仓库:

      kubernetes中的pause容器主要为每个业务容器提供以下功能:

        在pod中担任Linux命名空间共享的基础;

        启用pid命名空间,开启init进程。

      3、签发证书

    vim /opt/certs/kubelet-csr.json
      {
        "CN": "k8s-kubelet",
        "hosts": [
          "127.0.0.1",
          "192.168.112.10",
          "192.168.112.22",
          "192.168.112.23",
          "192.168.112.24",
          "192.168.112.25"
        ],
        "key": {
          "algo": "rsa",
          "size": 2048
        },
        "names": [
          {
            "C": "CN",
            "L": "BeiJing",
            "ST": "BeiJing",
            "O": "od",
            "OU": "ops"
          }
        ]
      }
    
    cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server kubelet-csr.json | cfssl-json -bare kubelet 

      4、拷贝配置文件(22、23)

    cd /opt/kubernetes/server/bin/cert/
    scp operations:/opt/certs/kubelet.pem ./
    scp operations:/opt/certs/kubelet-key.pem ./

       5、分发证书(22、23)

      # 设置集群参数
      kubectl config set-cluster myk8s 
      --certificate-authority=/opt/kubernetes/server/bin/cert/ca.pem 
      --embed-certs=true 
      --server=https://192.168.112.10:7443 
      --kubeconfig=kubelet.kubeconfig
    
      # 设置客户端认证参数
      kubectl config set-credentials k8s-node 
      --client-certificate=/opt/kubernetes/server/bin/cert/client.pem 
      --client-key=/opt/kubernetes/server/bin/cert/client-key.pem 
      --embed-certs=true 
      --kubeconfig=kubelet.kubeconfig
    
      # 设置上下文参数
      kubectl config set-context myk8s-context 
      --cluster=myk8s 
      --user=k8s-node 
      --kubeconfig=kubelet.kubeconfig
    
      # 设置当前使用的上下文
      kubectl config use-context myk8s-context --kubeconfig=kubelet.kubeconfig

    cd /opt/kubernetes/server/bin/conf
    scp operations:/opt/certs/kubelet.kubeconfig ./

       6、创建k8s-node.yaml文件(22节点上:不论在哪个节点创建,已经同步到etcd上。)

    vim k8s-node.yaml
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: k8s-node
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:node
    subjects:
    - apiGroup: rbac.authorization.k8s.io
      kind: User
      name: k8s-node
    
    创建
    kubectl create -f k8s-node.yaml
    检测
    kubectl get clusterrolebinding  k8s-node -o yaml

             

       7、在运维主机上

    docker pull kubernetes/pause
    docker tag f9d5de079539 harbor.od.com/public/pause:latest
    docker push harbor.od.com/public/pause:latest

      8、编辑kubelet启动脚本

    vim /opt/kubernetes/server/bin/kubelet.sh
    #!/bin/sh
    ./kubelet 
      --anonymous-auth=false 
      --cgroup-driver systemd 
      --cluster-dns 192.168.0.2 
      --cluster-domain cluster.local 
      --runtime-cgroups=/systemd/system.slice 
      --kubelet-cgroups=/systemd/system.slice 
      --fail-swap-on="false" 
      --client-ca-file ./cert/ca.pem 
      --tls-cert-file ./cert/kubelet.pem 
      --tls-private-key-file ./cert/kubelet-key.pem 
      --hostname-override slave3.host.com 
      --image-gc-high-threshold 20 
      --image-gc-low-threshold 10 
      --kubeconfig ./conf/kubelet.kubeconfig 
      --log-dir /data/logs/kubernetes/kube-kubelet 
      --pod-infra-container-image harbor.od.com/public/pause:latest 
      --root-dir /data/kubelet
    chmod u+x /opt/kubernetes/server/bin/kubelet.sh
    创建日志存储目录: mkdir -p /data/logs/kubernetes/kube-kubelet

      9、编辑supervisord启动文件:红色部分自行修改

    vi /etc/supervisord.d/kube-kubelet.ini
    
    [program:kube-kubelet-7-62]
    command=/opt/kubernetes/server/bin/kubelet.sh     ; the program (relative uses PATH, can take args)
    numprocs=1                                        ; number of processes copies to start (def 1)
    directory=/opt/kubernetes/server/bin              ; directory to cwd to before exec (def no cwd)
    autostart=true                                    ; start at supervisord start (default: true)
    autorestart=true                                  ; retstart at unexpected quit (default: true)
    startsecs=30                                      ; number of secs prog must stay running (def. 1)
    startretries=3                                    ; max # of serial start failures (default 3)
    exitcodes=0,2                                     ; 'expected' exit codes for process (default 0,2)
    stopsignal=QUIT                                   ; signal used to kill process (default TERM)
    stopwaitsecs=10                                   ; max num secs to wait b4 SIGKILL (default 10)
    user=root                                         ; setuid to this UNIX account to run the program
    redirect_stderr=true                              ; redirect proc stderr to stdout (default false)
    stdout_logfile=/data/logs/kubernetes/kube-kubelet/kubelet.stdout.log   ; stderr log path, NONE for none; default AUTO
    stdout_logfile_maxbytes=64MB                      ; max # logfile bytes b4 rotation (default 50MB)
    stdout_logfile_backups=4                          ; # of stdout logfile backups (default 10)
    stdout_capture_maxbytes=1MB                       ; number of bytes in 'capturemode' (default 0)
    stdout_events_enabled=false                       ; emit events on stdout writes (default false)
    
    supervisorctl update
    supervisorctl status

      10、查看节点是否加到集群

    kubectl get nodes
      NAME              STATUS   ROLES    AGE    VERSION
      slave3.host.com   Ready    <none>   101s   v1.15.2
      slave4.host.com   Ready    <none>   29s    v1.15.2
    
      
      kubectl label node slave3.host.com node-role.kubernetes.io/master=
      kubectl label node slave3.host.com node-role.kubernetes.io/node=
      kubectl label node slave4.host.com node-role.kubernetes.io/master=
      kubectl label node slave4.host.com node-role.kubernetes.io/node=
    
    kubectl get nodes

     

  • 相关阅读:
    64位操作系统Visual Studio连接本机oracle的问题
    解决Oracle启动失败
    通过应用程序域AppDomain加载和卸载程序集
    C#应用程序实现单例模式
    不实现 INotifyPropertyChanged接口也能实现数据绑定
    WPF弹出“选择文件夹”对话框
    Linux常用命令
    markedown基本语法
    git使用
    用户打开浏览器,输入buidu.com页面展示百度首页。整个过程发生了什么?
  • 原文地址:https://www.cnblogs.com/aqicheng/p/14439947.html
Copyright © 2020-2023  润新知