0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

Kubernetes的集群部署

汽车电子技术 来源:码农与软件时代 作者: 码农与软件时代 2023-02-15 10:35 次阅读

一、集群部署简介

1、Kubeadm

Kubeadm是一种Kubernetes集群部署工具,通过kubeadm init命令创建master节点,通过 kubeadm join命令把node节点加入到集群中。

kubeadm init大约会做这些事情:

①预检测:检查系统状态(Linux cgroups、10250/10251/10252端口是否可用 ),给出警告、错误信息,并会退出 kubeadm init命令执行;

②生成证书:生成的证书放在/etc/kubernetes/pki目录,以便访问kubernetes时使用;

③生成各组件YAML文件;

④安装集群最小可用插件。

其他Node节点使用kubeadm init生成的token,执行kubeadm join命令,就可以加入集群了。Node节点要先安装kubelet、kubeadm。

有关kubeadm init和kubeadm join命令的解释,参考:

https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/
https://kubernetes.io/zh/docs/reference/setup-tools/kubeadm/kubeadm-join

2、Kubelet

kubelet是用来操作Pod和容器的组件,运行在集群的所有节点上,需要直接安装在宿主机上。安装过程中,kubeadm调用kubelet实现kubeadm init的工作。

3、Kubectl

kubectl是Kubernetes集群的命令行工具,通过kubectl能够对集群本身进行管理,并能够在集群上进行容器化应用的安装部署。

二、集群安装

1、环境准备

Ubuntu 18.04 LTS CPU 2核 内存4G 硬盘 20G

同样规格:3台设备,hostname分别为master、node1、node2

2、Master节点安装

(1)设置hostname

root@k8s:/# hostnamectl --static set-hostname master
root@k8s:/# hostnamectl
   Static hostname: master
Transient hostname: k8s
         Icon name: computer-vm
           Chassis: vm
        Machine ID: e5c0d0f18ba04c0a8722ab9fff662987
           Boot ID: 74af5268dfe74f23b3dee608ab2afe41
    Virtualization: kvm
  Operating System: Ubuntu 18.04.2 LTS
            Kernel: Linux 4.15.0-122-generic
      Architecture: x86-64

(2)关闭系统Swap:执行命令swapoff-a 。

(3)安装docker社区版

apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y update
apt-get -y install docker-ce

(4)安装 kubelet 、kubeadm 、kubectl工具

apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat </etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl

3、Node1节点安装

重复Master节点安装的(1)~(4)

4、创建集群

(1)Master节点执行kubeadm init指令

kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16

成功日志的信息如下:

root@k8s:~# kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.23.1
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Using existing ca certificate authority
[certs] Using existing apiserver certificate and key on disk
[certs] Using existing apiserver-kubelet-client certificate and key on disk
[certs] Using existing front-proxy-ca certificate authority
[certs] Using existing front-proxy-client certificate and key on disk
[certs] Using existing etcd/ca certificate authority
[certs] Using existing etcd/server certificate and key on disk
[certs] Using existing etcd/peer certificate and key on disk
[certs] Using existing etcd/healthcheck-client certificate and key on disk
[certs] Using existing apiserver-etcd-client certificate and key on disk
[certs] Using the existing "sa" key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/admin.conf"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/kubelet.conf"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/controller-manager.conf"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/scheduler.conf"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 7.503605 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.23" in namespace kube-system with the configuration for the kubelets in the cluster
NOTE: The "kubelet-config-1.23" naming of the kubelet ConfigMap is deprecated. Once the UnversionedKubeletConfigMap feature gate graduates to Beta the default name will become just "kubelet-config". Kubeadm upgrade will handle this transition transparently.
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node master as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: e16km1.69phwhcdjaulf060
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully!


To start using your cluster, you need to run the following as a regular user:


  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config


Alternatively, if you are the root user, you can run:


  export KUBECONFIG=/etc/kubernetes/admin.conf


You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/


Then you can join any number of worker nodes by running the following on each as root:


kubeadm join 30.0.1.180:6443 --token e16km1.69phwhcdjaulf060 \\
  --discovery-token-ca-cert-hash sha256:2d3f77ae7598fb7709655b381af5fda8896d5a97cdf7176ff74a2aa25fca271c

kubeadm init 结束时,加入集群的命令信息会被打印出来,直接拷贝到需要加入的节点执行就可以了。

上面是比较顺利的步骤,实际操作过程中可能会遇到的如下问题:

Unfortunately, an error has occurred:
      timed out waiting for the condition


    This error is likely caused by:
      - The kubelet is not running
      - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)


  If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
    - 'systemctl status kubelet'
    - 'journalctl -xeu kubelet'


  Additionally, a control plane component may have crashed or exited when started by the container runtime.
  To troubleshoot, list all containers using your preferred container runtimes CLI.


  Here is one example how you may list all Kubernetes containers running in docker:
    - 'docker ps -a | grep kube | grep -v pause'
    Once you have found the failing container, you can inspect its logs with:
    - 'docker logs CONTAINERID'

原因为:

Cgroup Driver的值不同,docker的Cgroup Driver: cgroupfs,而kubernetes为systemd。

root@k8s:/# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
  scan: Docker Scan (Docker Inc., v0.12.0)


Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 7
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-122-generic
 Operating System: Ubuntu 18.04.2 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.852GiB
 Name: master
 ID: TNT3:2XIE:OCQQ:EZXX:DOVR:HJ7G:ASDH:XYFE:VZSO:YA5R:O2TU:IUVO
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

修改的方法为:在/etc/docker/daemon.json文件中(没文件则创建)增加如下内容:

{
  "exec-opts": ["native.cgroupdriver=systemd"]
}

重启docker

systemctl restart docker

再次执行kube-init,报错:

[init] Using Kubernetes version: v1.23.1
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
  [ERROR Port-6443]: Port 6443 is in use
  [ERROR Port-10259]: Port 10259 is in use
  [ERROR Port-10257]: Port 10257 is in use
  [ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists
  [ERROR FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml]: /etc/kubernetes/manifests/kube-controller-manager.yaml already exists
  [ERROR FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml]: /etc/kubernetes/manifests/kube-scheduler.yaml already exists
  [ERROR FileAvailable--etc-kubernetes-manifests-etcd.yaml]: /etc/kubernetes/manifests/etcd.yaml already exists
  [ERROR Port-10250]: Port 10250 is in use
  [ERROR Port-2379]: Port 2379 is in use
  [ERROR Port-2380]: Port 2380 is in use
  [ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

修改方法为:

root@k8s:~# netstat -nplt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:10257         0.0.0.0:*               LISTEN      3289/kube-controlle 
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      998/Xtightvnc       
tcp        0      0 127.0.0.1:10259         0.0.0.0:*               LISTEN      3311/kube-scheduler 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      601/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      948/sshd            
tcp        0      0 0.0.0.0:39451           0.0.0.0:*               LISTEN      1052/xfce4-session  
tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      2593/kubelet        
tcp        0      0 30.0.1.180:2379         0.0.0.0:*               LISTEN      3300/etcd           
tcp        0      0 127.0.0.1:2379          0.0.0.0:*               LISTEN      3300/etcd           
tcp        0      0 30.0.1.180:2380         0.0.0.0:*               LISTEN      3300/etcd           
tcp        0      0 127.0.0.1:2381          0.0.0.0:*               LISTEN      3300/etcd           
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      998/Xtightvnc       
tcp        0      0 127.0.0.1:36431         0.0.0.0:*               LISTEN      2593/kubelet        
tcp6       0      0 :::21                   :::*                    LISTEN      701/vsftpd          
tcp6       0      0 :::22                   :::*                    LISTEN      948/sshd            
tcp6       0      0 :::10250                :::*                    LISTEN      2593/kubelet        
tcp6       0      0 :::6443                 :::*                    LISTEN      3349/kube-apiserver 
tcp6       0      0 :::35407                :::*                    LISTEN      1052/xfce4-session  
root@k8s:~# kill -9 3349 3311 3289 2593 3300 
root@k8s:~# netstat -nplt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      998/Xtightvnc       
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      601/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      948/sshd            
tcp        0      0 0.0.0.0:39451           0.0.0.0:*               LISTEN      1052/xfce4-session  
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      998/Xtightvnc       
tcp6       0      0 :::21                   :::*                    LISTEN      701/vsftpd          
tcp6       0      0 :::22                   :::*                    LISTEN      948/sshd            
tcp6       0      0 :::35407                :::*                    LISTEN      1052/xfce4-session

修订后,kubeadm init执行成功。

# 此时Master节点的状态为NotReady。
root@k8s:~# kubectl get nodes
NAME     STATUS     ROLES                  AGE     VERSION
master   NotReady   control-plane,master   6m13s   v1.23.1


# 拉取镜像的信息
root@k8s:~# kubeadm config images list
k8s.gcr.io/kube-apiserver:v1.23.1
k8s.gcr.io/kube-controller-manager:v1.23.1
k8s.gcr.io/kube-scheduler:v1.23.1
k8s.gcr.io/kube-proxy:v1.23.1
k8s.gcr.io/pause:3.6
k8s.gcr.io/etcd:3.5.1-0
k8s.gcr.io/coredns/coredns:v1.8.6


# coredns 处于Pending状态,原因为网络插件这未安装
root@k8s:~# kubectl get pods --all-namespaces
NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE
kube-system   coredns-6d8c4cb4d-ghvmj          0/1     Pending   0          14m
kube-system   coredns-6d8c4cb4d-p45mv          0/1     Pending   0          14m
kube-system   etcd-master                      1/1     Running   0          15m
kube-system   kube-apiserver-master            1/1     Running   0          15m
kube-system   kube-controller-manager-master   1/1     Running   0          15m
kube-system   kube-proxy-xswwz                 1/1     Running   0          14m
kube-system   kube-scheduler-master            1/1     Running   0          15m


root@k8s:~# journalctl -f -u kubelet.service
-- Logs begin at Sun 2019-05-05 16:25:08 CST. --
Dec 30 20:44:59 master kubelet[6501]: E1230 16:44:59.669150    6501 kubelet.go:2347] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"

**(2)Master节点安装flannel网络插件 **

执行指令安装flannel插件:

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f  kube-flannel.yml

安装flannel后,master节点处于ready状态。

flannel安装:
root@k8s:~# wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
--2021-12-30 20:47:48--  https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5177 (5.1K) [text/plain]
Saving to: âkube-flannel.ymlâ


kube-flannel.yml                       100%[===========================================================================>]   5.06K  --.-KB/s    in 0s      


2021-12-30 20:47:49 (21.4 MB/s) - âkube-flannel.ymlâ saved [5177/5177]


root@k8s:~# kubectl apply -f  kube-flannel.yml
Warning: policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created


root@k8s:~# kubectl get pods --all-namespaces
NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE
kube-system   coredns-6d8c4cb4d-ghvmj          1/1     Running   0          25m
kube-system   coredns-6d8c4cb4d-p45mv          1/1     Running   0          25m
kube-system   etcd-master                      1/1     Running   0          25m
kube-system   kube-apiserver-master            1/1     Running   0          25m
kube-system   kube-controller-manager-master   1/1     Running   0          25m
kube-system   kube-flannel-ds-ql282            1/1     Running   0          66s
kube-system   kube-proxy-xswwz                 1/1     Running   0          25m
kube-system   kube-scheduler-master            1/1     Running   0          25m


root@k8s:~# kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   26m   v1.23.1

(3)Node节点加入到集群中

执行指令,将node1加入集群

kubeadm join 30.0.1.180:6443 --token e16km1.69phwhcdjaulf060 --discovery-token-ca-cert-hash sha256:2d3f77ae7598fb7709655b381af5fda8896d5a97cdf7176ff74a2aa25fca271c

这个命令在Master节点初始化成功的日志中,也可以在Master节点执行命令获取:

kubeadm token create --print-join-command

成功的日志信息:

root@k8s:~# kubeadm join 30.0.1.180:6443 --token e16km1.69phwhcdjaulf060 --discovery-token-ca-cert-hash sha256:2d3f77ae7598fb7709655b381af5fda8896d5a97cdf7176ff74a2aa25fca271c
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
W1230 20:19:34.532570   26262 utils.go:69] The recommended value for "resolvConf" in "KubeletConfiguration" is: /run/systemd/resolve/resolv.conf; the provided value is: /run/systemd/resolve/resolv.conf
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...


This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.


Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

此时的节点信息为:

root@k8s:~# kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   61m   v1.23.1
node1    Ready                     13m   v1.23.1


root@k8s:~# kubectl label nodes node1 node-role.kubernetes.io/node=
node/node1 labeled
root@k8s:~# kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   67m   v1.23.1
node1    Ready    node                   18m   v1.23.1

可能遇到的问题:Master节点的问题1,依然会遇见,采用相同的解决方法。

(3)Node2执行与node1相同的操作

root@k8s:/# kubeadm join 30.0.1.180:6443 --token e16km1.69phwhcdjaulf060 --discovery-token-ca-cert-hash sha256:2d3f77ae7598fb7709655b381af5fda8896d5a97cdf7176ff74a2aa25fca271c 
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
W1230 23:22:10.274581   28114 utils.go:69] The recommended value for "resolvConf" in "KubeletConfiguration" is: /run/systemd/resolve/resolv.conf; the provided value is: /run/systemd/resolve/resolv.conf
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...


This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.


Run 'kubectl get nodes' on the control-plane to see this node join the cluster.


root@k8s:~# kubectl get nodes
NAME     STATUS   ROLES                  AGE     VERSION
master   Ready    control-plane,master   7h2m    v1.23.1
node1    Ready    node                   6h13m   v1.23.1
node2    Ready    node                   3m13s   v1.23.1

三、集群相关信息

1、kubernetes组件部署信息

# kubernetes组件基本上运行在POD中
root@k8s:~# kubectl get pods -o wide --all-namespaces
NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
kube-system   coredns-6d8c4cb4d-ghvmj          1/1     Running   0          17h   10.244.0.2   master   <none>           <none>
kube-system   coredns-6d8c4cb4d-p45mv          1/1     Running   0          17h   10.244.0.3   master   <none>           <none>
kube-system   etcd-master                      1/1     Running   0          17h   30.0.1.180   master   <none>           <none>
kube-system   kube-apiserver-master            1/1     Running   0          17h   30.0.1.180   master   <none>           <none>
kube-system   kube-controller-manager-master   1/1     Running   0          17h   30.0.1.180   master   <none>           <none>
kube-system   kube-flannel-ds-8qt6p            1/1     Running   0          16h   30.0.1.160   node1    <none>           <none>
kube-system   kube-flannel-ds-ql282            1/1     Running   0          17h   30.0.1.180   master   <none>           <none>
kube-system   kube-flannel-ds-zkt47            1/1     Running   0          10h   30.0.1.47    node2    <none>           <none>
kube-system   kube-proxy-pb9gn                 1/1     Running   0          10h   30.0.1.47    node2    <none>           <none>
kube-system   kube-proxy-xswwz                 1/1     Running   0          17h   30.0.1.180   master   <none>           <none>
kube-system   kube-proxy-zdfp5                 1/1     Running   0          16h   30.0.1.160   node1    <none>           <none>
kube-system   kube-scheduler-master            1/1     Running   0          17h   30.0.1.180   master   <none>           <none>


# kublet直接安装在宿主机上,不以docker形式运行
root@k8s:~# systemctl status kubelet.service
â kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/kubelet.service.d
           ââ10-kubeadm.conf
   Active: active (running) since Thu 2021-12-30 16:23:24 CST; 17h ago
     Docs: https://kubernetes.io/docs/home/
 Main PID: 6501 (kubelet)
    Tasks: 16 (limit: 4702)
   CGroup: /system.slice/kubelet.service
           ââ6501 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/li


root@k8s:~# docker ps
CONTAINER ID   IMAGE                                               COMMAND                  CREATED        STATUS        PORTS     NAMES
28bfaeeaadf1   a4ca41631cc7                                        "/coredns -conf /etcâ¦"   17 hours ago   Up 17 hours             k8s_coredns_coredns-6d8c4cb4d-p45mv_kube-system_4ce03d3c-1660-4975-8450-408515ec6a02_0
57a535a41123   a4ca41631cc7                                        "/coredns -conf /etcâ¦"   17 hours ago   Up 17 hours             k8s_coredns_coredns-6d8c4cb4d-ghvmj_kube-system_1a67722e-a15f-4bf0-bbd7-e2af542d2621_0
7be45271357a   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 17 hours ago   Up 17 hours             k8s_POD_coredns-6d8c4cb4d-p45mv_kube-system_4ce03d3c-1660-4975-8450-408515ec6a02_0
79776dc797f4   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 17 hours ago   Up 17 hours             k8s_POD_coredns-6d8c4cb4d-ghvmj_kube-system_1a67722e-a15f-4bf0-bbd7-e2af542d2621_0
424b5047009f   e6ea68648f0c                                        "/opt/bin/flanneld -â¦"   17 hours ago   Up 17 hours             k8s_kube-flannel_kube-flannel-ds-ql282_kube-system_9cb2439b-e8f4-422f-a72d-83370e75043e_0
51bea3cfeef7   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 17 hours ago   Up 17 hours             k8s_POD_kube-flannel-ds-ql282_kube-system_9cb2439b-e8f4-422f-a72d-83370e75043e_0
e6149ade3a29   b46c42588d51                                        "/usr/local/bin/kubeâ¦"   18 hours ago   Up 18 hours             k8s_kube-proxy_kube-proxy-xswwz_kube-system_12dac07f-e07e-4eff-becc-7b40a92f3adb_0
3c365b2342a0   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 18 hours ago   Up 18 hours             k8s_POD_kube-proxy-xswwz_kube-system_12dac07f-e07e-4eff-becc-7b40a92f3adb_0
b60a3b02f427   25f8c7f3da61                                        "etcd --advertise-clâ¦"   18 hours ago   Up 18 hours             k8s_etcd_etcd-master_kube-system_5d83471f981b1644e30c11cc642c68f7_0
abd1e3377560   b6d7abedde39                                        "kube-apiserver --adâ¦"   18 hours ago   Up 18 hours             k8s_kube-apiserver_kube-apiserver-master_kube-system_df535ce9e2ccfb931f8e46a9b80a6218_0
df5e2a226999   f51846a4fd28                                        "kube-controller-manâ¦"   18 hours ago   Up 18 hours             k8s_kube-controller-manager_kube-controller-manager-master_kube-system_85ff8159d8c894c53981716f8927f187_0
b45d17ab969f   71d575efe628                                        "kube-scheduler --auâ¦"   18 hours ago   Up 18 hours             k8s_kube-scheduler_kube-scheduler-master_kube-system_77a51208064a0e9b17209ee62638dfcd_0
3cf0d75ad0f0   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 18 hours ago   Up 18 hours             k8s_POD_kube-apiserver-master_kube-system_df535ce9e2ccfb931f8e46a9b80a6218_0
6b447aa2fd93   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 18 hours ago   Up 18 hours             k8s_POD_etcd-master_kube-system_5d83471f981b1644e30c11cc642c68f7_0
f7f9a3cd677f   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 18 hours ago   Up 18 hours             k8s_POD_kube-scheduler-master_kube-system_77a51208064a0e9b17209ee62638dfcd_0
20e0b291d166   registry.aliyuncs.com/google_containers/pause:3.6   "/pause"                 18 hours ago   Up 18 hours             k8s_POD_kube-controller-manager-master_kube-system_85ff8159d8c894c53981716f8927f187_0

2、网段:每个kubernetes node从中分配一个子网片段。

(1)Master节点

root@k8s:~# cat /run/flannel/subnet.env 
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.0.1/24
FLANNEL_MTU=1400
FLANNEL_IPMASQ=true

(2)Node1节点

root@k8s:~# cat /run/flannel/subnet.env 
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.1.1/24
FLANNEL_MTU=1400
FLANNEL_IPMASQ=true

(3)Node2节点

root@k8s:/# cat /run/flannel/subnet.env 
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.2.1/24
FLANNEL_MTU=1400
FLANNEL_IPMASQ=true

3、Kubernetes节点进程

(1)MASTER节点

root@k8s:~# ps -el | grep kube
4 S     0  6224  6152  0  80   0 - 188636 futex_ ?       00:05:00 kube-scheduler
4 S     0  6275  6196  1  80   0 - 206354 ep_pol ?       00:23:02 kube-controller
4 S     0  6287  6181  5  80   0 - 278080 futex_ ?       01:19:40 kube-apiserver
4 S     0  6501     1  3  80   0 - 487736 futex_ ?       00:46:38 kubelet
4 S     0  6846  6818  0  80   0 - 187044 futex_ ?       00:00:26 kube-proxy

(2)Node节点

# node1
root@k8s:~# ps -el | grep kube
4 S     0 22869 22845  0  80   0 - 187172 futex_ ?       00:00:23 kube-proxy
4 S     0 26395     1  2  80   0 - 505977 futex_ ?       00:28:10 kubelet
# node2
root@k8s:/# ps -el | grep kube
4 S     0 28227     1  1  80   0 - 487480 futex_ ?       00:17:26 kubelet
4 S     0 28724 28696  0  80   0 - 187044 futex_ ?       00:00:17 kube-proxy
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • MASTER
    +关注

    关注

    0

    文章

    78

    浏览量

    11158
  • init
    +关注

    关注

    0

    文章

    15

    浏览量

    3379
  • node
    +关注

    关注

    0

    文章

    20

    浏览量

    5881
  • kubernetes
    +关注

    关注

    0

    文章

    219

    浏览量

    8568
收藏 人收藏

    评论

    相关推荐

    阿里云上Kubernetes集群联邦

    摘要: kubernetes集群让您能够方便的部署管理运维容器化的应用。但是实际情况中经常遇到的一些问题,就是单个集群通常无法跨单个云厂商的多个Region,更不用说支持跨跨域不同的云
    发表于 03-12 17:10

    使用Helm 在容器服务k8s集群一键部署wordpress

    摘要: Helm 是啥? 微服务和容器化给复杂应用部署与管理带来了极大的挑战。Helm是目前Kubernetes服务编排领域的唯一开源子项目,做为Kubernetes应用的一个包管理工具,可理解
    发表于 03-29 13:38

    Kubernetes Ingress 高可靠部署最佳实践

    摘要: 在Kubernetes集群中,Ingress作为集群流量接入层,Ingress的高可靠性显得尤为重要,今天我们主要探讨如何部署一套高性能高可靠的Ingress接入层。简介
    发表于 04-17 14:35

    阿里云宣布推出Serverless Kubernetes服务 30秒即可完成应用部署

    Serverless形态。开发者可在5秒内创建集群、30秒部署应用上线。用户无需管理集群基础设施,还可根据应用实际消耗资源按量付费,此举意在进一步降低容器技术的使用门槛,简化容器平台运维的复杂度。该服
    发表于 05-03 15:38

    Flink集群部署方法

    Flink集群部署详细步骤
    发表于 04-23 11:45

    kubernetes集群配置

    基于v1104版本手动搭建高可用kubernetes 集群
    发表于 08-19 08:07

    Kubernetes 从懵圈到熟练:集群服务的三个要点和一种实现

    照进现实前边两节,我们看到了,Kubernetes 集群的服务,本质上是负载均衡,即反向代理;同时我们知道了,在实际实现中,这个反向代理,并不是部署集群某一个节点上,而是作为
    发表于 09-24 15:35

    kubernetes v112二进制方式集群部署

    kubernetes v112 二进制方式集群部署
    发表于 05-05 16:30

    redis集群的如何部署

    redis集群部署(伪分布式)
    发表于 05-29 17:13

    请问鸿蒙系统上可以部署kubernetes集群吗?

    鸿蒙系统上可以部署kubernetes集群
    发表于 06-08 11:16

    如何部署基于Mesos的Kubernetes集群

    的内核。把Kubernetes运行在Mesos集群之上,可以和其他的框架共享集群资源,提高集群资源的利用率。 本文是Kubernetes和M
    发表于 10-09 18:04 0次下载
    如何<b class='flag-5'>部署</b>基于Mesos的<b class='flag-5'>Kubernetes</b><b class='flag-5'>集群</b>

    浅谈Kubernetes集群的高可用方案

    Kubernetes作为容器应用的管理中心,通过对Pod的数量进行监控,并且根据主机或容器失效的状态将新的Pod调度到其他Node上,实现了应用层的高可用性。针对Kubernetes集群,高可用性
    发表于 10-11 10:04 1次下载
    浅谈<b class='flag-5'>Kubernetes</b><b class='flag-5'>集群</b>的高可用方案

    Kubernetes 集群的功能

    Telepresence 是一个开源工具,可让您在本地运行单个服务,同时将该服务连接到远程 Kubernetes 集群
    的头像 发表于 09-05 10:58 804次阅读

    Kubernetes集群的关闭与重启

    在日常对 Kubernetes 集群运行维护的过程中,您可能需要临时的关闭或者是重启 Kubernetes 集群集群进行维护,本文将介绍如
    的头像 发表于 11-07 09:50 8741次阅读

    Kubernetes集群部署一个ChatGPT机器人

    Robusta 有一个用于集成的 UI,也有一个预配置的 Promethus 系统,如果你还没有自己的 K8s 集群,并且想尝试一下这个 ChatGPT 机器人,你可以使用 Robusta 现有的!
    的头像 发表于 03-07 09:33 972次阅读