K8S k8s(3)__Node搭建 发表于 2022-09-02 浏览量 376 没有评论 # Node二进制搭建 创建对应目录: `mkdir -pv /usr/local/kubernetes/{conf,bin,logs}` # K8s的Node组件 拷贝Kubelet,Kube-proxy,kubectl到node节点上,这些在server包上。 Kubelet组件:确保容器的运行,管理由K8s创建的容器 Kube-proxy:维护容器的网络规则 Docker: 容器运行环境 # 环境变量设置 ``` vim /usr/local/kubernetes/conf/kubernetes KUBE_MASTER="--master=192.168.237.50:8080" KUBE_LOG_LEVEL="--v=2" KUBE_LOGTOSTDERR="--logtostderr=false" KUBE_LOG_DIR="--log-dir=/usr/local/kubernetes/logs/" ``` # Kube-proxy的启动 ``` vim /usr/lib/systemd/system/kube-proxy.service [Unit] Description=kube-proxy After=network.target [Service] EnvironmentFile=-/usr/local/kubernetes/conf/kubernetes ExecStart=/usr/local/kubernetes/bin/kube-proxy \ $KUBE_MASTER \ $KUBE_LOG_LEVEL \ $KUBE_LOGTOSTDERR \ $KUBE_LOG_DIR [Install] WantedBy=multi-user.target ``` # 查看docker是cgroupfs驱动类型 `docker info |grep 'Cgroup Driver'` 下面的配置文件2选1哦!!!! # Kubelet配置文件1(systemd类型) ``` vim /usr/local/kubernetes/conf/kubelet KUBELET_ADDRESS="--address=xxx" KUBELET_ARGS="--kubeconfig=/usr/local/kubernetes/conf/kubeconfig --runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice --cgroup-driver=systemd --enable-server=true --enable-debugging-handlers=true" ``` # Kubelet配置文件2(Cgroup类型) ``` vim /usr/local/kubernetes/conf/kubelet KUBELET_ADDRESS="--address=xxx" KUBELET_ARGS="--kubeconfig=/usr/local/kubernetes/conf/kubeconfig --cgroup-driver=cgroupfs --enable-server=true --enable-debugging-handlers=true" ``` # kubeconfig配置文件 ``` vim /usr/local/kubernetes/conf/kubeconfig apiVersion: v1 kind: Config users: - name: kubelet clusters: - name: kubernetes cluster: server: 192.168.237.50:8080 contexts: - context: cluster: kubernetes user: kubelet name: default current-context: default ``` # Kubelete的启动配置 ``` vim /usr/lib/systemd/system/kubelet.service [Unit] Description=kubelet After=docker.target [Service] EnvironmentFile=-/usr/local/kubernetes/conf/kubernetes EnvironmentFile=-/usr/local/kubernetes/conf/kubelet ExecStart=/usr/local/kubernetes/bin/kubelet \ $KUBE_LOGTOSTDERR \ $KUBE_LOG_LEVEL \ $KUBE_LOG_DIR \ $KUBELET_ADDRESS \ $KUBELET_ARGS [Install] WantedBy=multi-user.target ``` Master上查看是否有Node节点的注册 kubectl --server=192.168.237.50:8080 get node 搭建两台Node,后面课程有用到 # 报错及解决办法 启动Kubelet时报错 ``` failed to run Kubelet: Running with swap on is not supported, please disable swap! or set --fail-swap-on flag to false. /proc/swaps contained ``` - 关闭交换分区 swapoff -a