• 一、k8s的安装部署


    目录

    k8s是什么?有什么作用?

    CNCF是什么?

     k8s里面有哪些组件?

    k8s架构图 

    k8s的安装部署

    1、IP地址规划:

    2、关闭firewalld和selinux(在k8s集群master和node上都进行操作)

    3、在所有机器上安装docker

    安装yum相关工具,下载docker-ce.repo文件

     安装docker-ce软件

    启动docker服务,设置docker开机自启

    4、关闭交换分区

    5、重新命名主机名,并修改hosts文件

    6、修改一些内核参数

     7、安装kubadm,kubctl,kublet软件

    8、部署kubernetes master

    9、将node节点服务器加入k8s集群

    10.安装网络插件flannel(在master节点执行) 

     部署flannel

     查看集群状态(状态为Ready就代表k8s部署成功)

    查看各个节点详细信息

    查看k8s里的命名空间有哪些(k8s自己创建的) 

    查看pod运行在哪个node上,


    k8s是什么?有什么作用?

            kubernetes 是 k8s的全称

            k8s是用来管理容器的,可以用来管理容器的,可以用来部署,扩缩,管理容器

            有代码的地方就可以有k8s

    容器运行时软件:

            管理容器从创建,启动,关闭,镜像相关的操作的软件

            docker

            coreos 

    CNCF是什么?

    CNCF,全称 Cloud Native Computing Foundation,译为云原生计算机基金会

     k8s里面有哪些组件?

    从角色上来讲的话:master(管理节点)和node(工作节点)

    master上的control plane 组件:

            1、kube-apiserver 

                    组件:就是一个pod,pod里面有很多的容器,运行相关的软件,会有相应的docker镜像文件

                    API服务器时Kubernetes 控制平面的组件,该组件负责公开了kubernetes API,负责处理接受请求的工作,api服务器时Kubernetes 控制平面的前端

                    k8s的入口,通过这个接口可以了解整个k8s的信息和资源

            2、etcd:高可用的键值数据库,保存Kubernetes所有集群数据的后台数据库

            3、scheduler 调度器:负责监视新创建的,未指定运行节点(node)的pods,并选择节点来让Pod在上面运行

                            pod:是k8s里最小的计算单元,里面可以包含很多的容器,所有的容器共享一个ip地址

            4、controller-manager 控制器的管理创新

                            k8s有很多的控制器

                                    deployment 部署pod的控制器

                                    replicaSET  副本控制器

            5、cloud-controller-manager 

                            一个Kubernetes 控制平面组件,嵌入了特定于云平台的控制逻辑,云控制器管理器(cloud controller Manager)允许你将你的集群连接到云提供商的API之上,并将于该平台交互的组件同与你的集群交互的组件分离开来

    Node组件

            1、kubelet 会在集群中每个节点(node)上运行,它保证容器(containers)都运行在pod中,启动pod会在node节点服务器上

            2、kube-proxy  维护节点上的一些网络规则,这些网络规则会允许从集群内部或外部的网络会话与pod进行网络通信

                    网络通信:多个node之间的网络通信,负载均衡

    k8s的使用

            pod

            pv

            pvc

            控制器

            hpa

    #############################################################################  

    k8s架构图 

    #############################################################################  

    k8s的安装部署

            1、minikube

            2、kubeadm    k8s官方推荐的安装k8s的方式

            3、二进制安装

            4、第3方的部署工具:rancher等

    k8s集群的架构

            1、单master和多node

            2、多master和多node  -- 高可用

                    3master  3node  1个负载均衡(nginx)

    实验环境

            1台master,3台node

            软件:centos7.9  docker

            硬件:2G/2c

    1、IP地址规划:

            k8s-master:192.168.44.210

            k8s-node1:192.168.44.211

            k8s-node2:192.168.44.212

            k8s-node3:192.168.44.213

    ############################################################################# 

    2、关闭firewalld和selinux(在k8s集群master和node上都进行操作)

    1. [root@k8s-master ~]# service firewalld stop
    2. Redirecting to /bin/systemctl stop firewalld.service
    3. [root@k8s-master ~]# systemctl disable firewalld
    4. Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
    5. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    6. [root@k8s-master ~]# setenforce 0
    7. [root@k8s-master ~]# getenforce
    8. Permissive

    ############################################################################# 

    3、在所有机器上安装docker

    安装yum相关工具,下载docker-ce.repo文件

    yum install -y yum-utils
    1. yum-config-manager \
    2. --add-repo \
    3. https://download.docker.com/linux/centos/docker-ce.repo

     安装docker-ce软件

    yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
    

    启动docker服务,设置docker开机自启

    1. [root@k8s-master yum.repos.d]# systemctl start docker
    2. [root@k8s-master yum.repos.d]# ps aux|grep docker
    3. root 11877 6.1 2.6 1027340 48624 ? Ssl 17:35 0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    4. root 12001 0.0 0.0 112824 976 pts/0 S+ 17:35 0:00 grep --color=auto docker
    5. [root@k8s-master yum.repos.d]# systemctl enable docker
    6. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
    7. [root@k8s-master yum.repos.d]#

    #############################################################################

    4、关闭交换分区

    1. [root@k8s-master yum.repos.d]# swapoff -a
    2. [root@k8s-master yum.repos.d]# free -m
    3. total used free shared buff/cache available
    4. Mem: 1819 298 779 9 741 1354
    5. Swap: 0 0 0
    6. [root@k8s-master yum.repos.d]#

    #############################################################################

    5、重新命名主机名,并修改hosts文件

    1. [root@k8s-master yum.repos.d]# cat >> /etc/hosts << EOF
    2. > 192.168.44.210 k8s-master
    3. > 192.168.44.211 k8s-node1
    4. > 192.168.44.212 k8s-node2
    5. > 192.168.44.213 k8s-node3
    6. > EOF

    ############################################################################# 

    6、修改一些内核参数

    1. [root@k8s-master yum.repos.d]# cat <> /etc/sysctl.conf
    2. > net.bridge.bridge-nf-call-ip6tables = 1
    3. > net.bridge.bridge-nf-call-iptables = 1
    4. > net.ipv4.ip_nonlocal_bind = 1
    5. > net.ipv4.ip_forward = 1
    6. > vm.swappiness=0
    7. > EOF

    sysctl -p 让参数生效到内核里面

    1. [root@k8s-master yum.repos.d]# sysctl -p
    2. net.bridge.bridge-nf-call-ip6tables = 1
    3. net.bridge.bridge-nf-call-iptables = 1
    4. net.ipv4.ip_nonlocal_bind = 1
    5. net.ipv4.ip_forward = 1
    6. vm.swappiness = 0

    #############################################################################

     7、安装kubadm,kubctl,kublet软件

    添加kubernetes yum软件源

    1. [root@k8s-master ~]# cat > /etc/yum.repos.d/kubernetes.repo << EOF
    2. > [kubernetes]
    3. > name=Kubernetes
    4. > baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
    5. > enabled=1
    6. > gpgcheck=0
    7. > repo_gpgcheck=0
    8. > gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    9. > EOF

    安装kubeadm,kubelet,kubectl,并且指定版本,因为1.24的版本默认运行时环境不是docker了

    yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6

    设置开机自启,因为kubelet是k8s在node节点上的代理,必须开机要运行的

    1. [root@k8s-master ~]# systemctl enable kubelet
    2. Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

    #############################################################################

    8、部署kubernetes master

     提前准备coredns:1.8.4的镜像,后面需要使用,需要在每台机器上下载镜像

    1. [root@k8s-master ~]# docker pull coredns/coredns:1.8.4
    2. 1.8.4: Pulling from coredns/coredns
    3. c6568d217a00: Pull complete
    4. bc38a22c706b: Pull complete
    5. Digest: sha256:6e5a02c21641597998b4be7cb5eb1e7b02c0d8d23cce4dd09f4682d463798890
    6. Status: Downloaded newer image for coredns/coredns:1.8.4
    7. docker.io/coredns/coredns:1.8.4
    8. [root@k8s-master ~]# docker images
    9. REPOSITORY TAG IMAGE ID CREATED SIZE
    10. coredns/coredns 1.8.4 8d147537fb7d 16 months ago 47.6MB
    11. [root@k8s-master ~]# docker tag coredns/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4
    12. [root@k8s-master ~]# docker images
    13. REPOSITORY TAG IMAGE ID CREATED SIZE
    14. coredns/coredns 1.8.4 8d147537fb7d 16 months ago 47.6MB
    15. registry.aliyuncs.com/google_containers/coredns v1.8.4 8d147537fb7d 16 months ago 47.6MB

    在master服务器上进行初始化操作

    1. [root@k8s-master ~]# kubeadm init \
    2. > --apiserver-advertise-address=192.168.44.210 \
    3. > --image-repository registry.aliyuncs.com/google_containers \
    4. > --service-cidr=10.1.0.0/16 \
    5. > --pod-network-cidr=10.244.0.0/16
    6. I0924 22:36:57.310381 20845 version.go:255] remote version is much newer: v1.25.2; falling back to: stable-1.23
    7. [init] Using Kubernetes version: v1.23.12
    8. [preflight] Running pre-flight checks
    9. [preflight] Pulling images required for setting up a Kubernetes cluster
    10. [preflight] This might take a minute or two, depending on the speed of your internet connection
    11. [preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
    12. [certs] Using certificateDir folder "/etc/kubernetes/pki"
    13. [certs] Generating "ca" certificate and key
    14. [certs] Generating "apiserver" certificate and key
    15. [certs] apiserver serving cert is signed for DNS names [k8s-master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.1.0.1 192.168.44.210]
    16. [certs] Generating "apiserver-kubelet-client" certificate and key
    17. [certs] Generating "front-proxy-ca" certificate and key
    18. [certs] Generating "front-proxy-client" certificate and key
    19. [certs] Generating "etcd/ca" certificate and key
    20. [certs] Generating "etcd/server" certificate and key
    21. [certs] etcd/server serving cert is signed for DNS names [k8s-master localhost] and IPs [192.168.44.210 127.0.0.1 ::1]
    22. [certs] Generating "etcd/peer" certificate and key
    23. [certs] etcd/peer serving cert is signed for DNS names [k8s-master localhost] and IPs [192.168.44.210 127.0.0.1 ::1]
    24. [certs] Generating "etcd/healthcheck-client" certificate and key
    25. [certs] Generating "apiserver-etcd-client" certificate and key
    26. [certs] Generating "sa" key and public key
    27. [kubeconfig] Using kubeconfig folder "/etc/kubernetes"
    28. [kubeconfig] Writing "admin.conf" kubeconfig file
    29. [kubeconfig] Writing "kubelet.conf" kubeconfig file
    30. [kubeconfig] Writing "controller-manager.conf" kubeconfig file
    31. [kubeconfig] Writing "scheduler.conf" kubeconfig file
    32. [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
    33. [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
    34. [kubelet-start] Starting the kubelet
    35. [control-plane] Using manifest folder "/etc/kubernetes/manifests"
    36. [control-plane] Creating static Pod manifest for "kube-apiserver"
    37. [control-plane] Creating static Pod manifest for "kube-controller-manager"
    38. [control-plane] Creating static Pod manifest for "kube-scheduler"
    39. [etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
    40. [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
    41. [apiclient] All control plane components are healthy after 7.503688 seconds
    42. [upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
    43. [kubelet] Creating a ConfigMap "kubelet-config-1.23" in namespace kube-system with the configuration for the kubelets in the cluster
    44. 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.
    45. [upload-certs] Skipping phase. Please see --upload-certs
    46. [mark-control-plane] Marking the node k8s-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]
    47. [mark-control-plane] Marking the node k8s-master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
    48. [bootstrap-token] Using token: 0xp3gm.wzbsahhxwa1dtaeh
    49. [bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
    50. [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
    51. [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
    52. [bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
    53. [bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
    54. [bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
    55. [kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
    56. [addons] Applied essential addon: CoreDNS
    57. [addons] Applied essential addon: kube-proxy
    58. Your Kubernetes control-plane has initialized successfully!
    59. To start using your cluster, you need to run the following as a regular user:
    60. mkdir -p $HOME/.kube
    61. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    62. sudo chown $(id -u):$(id -g) $HOME/.kube/config
    63. Alternatively, if you are the root user, you can run:
    64. export KUBECONFIG=/etc/kubernetes/admin.conf
    65. You should now deploy a pod network to the cluster.
    66. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
    67. https://kubernetes.io/docs/concepts/cluster-administration/addons/
    68. Then you can join any number of worker nodes by running the following on each as root:
    69. kubeadm join 192.168.44.210:6443 --token 0xp3gm.wzbsahhxwa1dtaeh \
    70. --discovery-token-ca-cert-hash sha256:bc28a61b1de3bfa7cb95c619ef050fe67238471347b16d9e34e400e405efe0bb
    71. [root@k8s-master ~]#

    完成初始化的新建文件和目录的操作,在master上完成 

    1. [root@k8s-master ~]# mkdir -p $HOME/.kube
    2. [root@k8s-master ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    3. [root@k8s-master ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config

    ############################################################################# 

    9、将node节点服务器加入k8s集群

    在三台node节点服务器上都执行

    1. [root@k8s-node1 ~]# kubeadm join 192.168.44.210:6443 --token 0xp3gm.wzbsahhxwa1dtaeh --discovery-token-ca-cert-hash sha256:bc28a61b1de3bfa7cb95c619ef050fe67238471347b16d9e34e400e405efe0bb
    2. [preflight] Running pre-flight checks
    3. [preflight] Reading configuration from the cluster...
    4. [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
    5. [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
    6. [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
    7. [kubelet-start] Starting the kubelet
    8. [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
    9. This node has joined the cluster:
    10. * Certificate signing request was sent to apiserver and a response was received.
    11. * The Kubelet was informed of the new secure connection details.
    12. Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
    1. [root@k8s-node2 ~]# kubeadm join 192.168.44.210:6443 --token 0xp3gm.wzbsahhxwa1dtaeh --discovery-token-ca-cert-hash sha256:bc28a61b1de3bfa7cb95c619ef050fe67238471347b16d9e34e400e405efe0bb
    2. [preflight] Running pre-flight checks
    3. [preflight] Reading configuration from the cluster...
    4. [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
    5. [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
    6. [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
    7. [kubelet-start] Starting the kubelet
    8. [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
    9. This node has joined the cluster:
    10. * Certificate signing request was sent to apiserver and a response was received.
    11. * The Kubelet was informed of the new secure connection details.
    12. Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
    1. [root@k8s-node3 ~]# kubeadm join 192.168.44.210:6443 --token 0xp3gm.wzbsahhxwa1dtaeh --discovery-token-ca-cert-hash sha256:bc28a61b1de3bfa7cb95c619ef050fe67238471347b16d9e34e400e405efe0bb
    2. [preflight] Running pre-flight checks
    3. [preflight] Reading configuration from the cluster...
    4. [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
    5. [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
    6. [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
    7. [kubelet-start] Starting the kubelet
    8. [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
    9. This node has joined the cluster:
    10. * Certificate signing request was sent to apiserver and a response was received.
    11. * The Kubelet was informed of the new secure connection details.
    12. Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

    在master上查看node节点信息

    1. [root@k8s-master ~]# kubectl get nodes
    2. NAME STATUS ROLES AGE VERSION
    3. k8s-master NotReady control-plane,master 11m v1.23.6
    4. k8s-node1 NotReady 3m49s v1.23.6
    5. k8s-node2 NotReady 100s v1.23.6
    6. k8s-node3 NotReady 96s v1.23.6

    NotReady 说明master和node节点之间的通信还是有问题的,容器之间通信还没有准备好

    ############################################################################# 

    10.安装网络插件flannel(在master节点执行) 

     k8s的网络插件:作用就是实现不同宿主机之间pod的通信

            1、flannel  --》overlay --》vxlan

            2、calico  --》 ipip  BGP

    kube-flannel.yaml 文件需要自己去创建,内容如下:

    1. ---
    2. kind: Namespace
    3. apiVersion: v1
    4. metadata:
    5. name: kube-flannel
    6. labels:
    7. pod-security.kubernetes.io/enforce: privileged
    8. ---
    9. kind: ClusterRole
    10. apiVersion: rbac.authorization.k8s.io/v1
    11. metadata:
    12. name: flannel
    13. rules:
    14. - apiGroups:
    15. - ""
    16. resources:
    17. - pods
    18. verbs:
    19. - get
    20. - apiGroups:
    21. - ""
    22. resources:
    23. - nodes
    24. verbs:
    25. - list
    26. - watch
    27. - apiGroups:
    28. - ""
    29. resources:
    30. - nodes/status
    31. verbs:
    32. - patch
    33. ---
    34. kind: ClusterRoleBinding
    35. apiVersion: rbac.authorization.k8s.io/v1
    36. metadata:
    37. name: flannel
    38. roleRef:
    39. apiGroup: rbac.authorization.k8s.io
    40. kind: ClusterRole
    41. name: flannel
    42. subjects:
    43. - kind: ServiceAccount
    44. name: flannel
    45. namespace: kube-flannel
    46. ---
    47. apiVersion: v1
    48. kind: ServiceAccount
    49. metadata:
    50. name: flannel
    51. namespace: kube-flannel
    52. ---
    53. kind: ConfigMap
    54. apiVersion: v1
    55. metadata:
    56. name: kube-flannel-cfg
    57. namespace: kube-flannel
    58. labels:
    59. tier: node
    60. app: flannel
    61. data:
    62. cni-conf.json: |
    63. {
    64. "name": "cbr0",
    65. "cniVersion": "0.3.1",
    66. "plugins": [
    67. {
    68. "type": "flannel",
    69. "delegate": {
    70. "hairpinMode": true,
    71. "isDefaultGateway": true
    72. }
    73. },
    74. {
    75. "type": "portmap",
    76. "capabilities": {
    77. "portMappings": true
    78. }
    79. }
    80. ]
    81. }
    82. net-conf.json: |
    83. {
    84. "Network": "10.244.0.0/16",
    85. "Backend": {
    86. "Type": "vxlan"
    87. }
    88. }
    89. ---
    90. apiVersion: apps/v1
    91. kind: DaemonSet
    92. metadata:
    93. name: kube-flannel-ds
    94. namespace: kube-flannel
    95. labels:
    96. tier: node
    97. app: flannel
    98. spec:
    99. selector:
    100. matchLabels:
    101. app: flannel
    102. template:
    103. metadata:
    104. labels:
    105. tier: node
    106. app: flannel
    107. spec:
    108. affinity:
    109. nodeAffinity:
    110. requiredDuringSchedulingIgnoredDuringExecution:
    111. nodeSelectorTerms:
    112. - matchExpressions:
    113. - key: kubernetes.io/os
    114. operator: In
    115. values:
    116. - linux
    117. hostNetwork: true
    118. priorityClassName: system-node-critical
    119. tolerations:
    120. - operator: Exists
    121. effect: NoSchedule
    122. serviceAccountName: flannel
    123. initContainers:
    124. - name: install-cni-plugin
    125. #image: flannelcni/flannel-cni-plugin:v1.1.0 for ppc64le and mips64le (dockerhub limitations may apply)
    126. image: docker.io/rancher/mirrored-flannelcni-flannel-cni-plugin:v1.1.0
    127. command:
    128. - cp
    129. args:
    130. - -f
    131. - /flannel
    132. - /opt/cni/bin/flannel
    133. volumeMounts:
    134. - name: cni-plugin
    135. mountPath: /opt/cni/bin
    136. - name: install-cni
    137. #image: flannelcni/flannel:v0.19.1 for ppc64le and mips64le (dockerhub limitations may apply)
    138. image: docker.io/rancher/mirrored-flannelcni-flannel:v0.19.1
    139. command:
    140. - cp
    141. args:
    142. - -f
    143. - /etc/kube-flannel/cni-conf.json
    144. - /etc/cni/net.d/10-flannel.conflist
    145. volumeMounts:
    146. - name: cni
    147. mountPath: /etc/cni/net.d
    148. - name: flannel-cfg
    149. mountPath: /etc/kube-flannel/
    150. containers:
    151. - name: kube-flannel
    152. #image: flannelcni/flannel:v0.19.1 for ppc64le and mips64le (dockerhub limitations may apply)
    153. image: docker.io/rancher/mirrored-flannelcni-flannel:v0.19.1
    154. command:
    155. - /opt/bin/flanneld
    156. args:
    157. - --ip-masq
    158. - --kube-subnet-mgr
    159. resources:
    160. requests:
    161. cpu: "100m"
    162. memory: "50Mi"
    163. limits:
    164. cpu: "100m"
    165. memory: "50Mi"
    166. securityContext:
    167. privileged: false
    168. capabilities:
    169. add: ["NET_ADMIN", "NET_RAW"]
    170. env:
    171. - name: POD_NAME
    172. valueFrom:
    173. fieldRef:
    174. fieldPath: metadata.name
    175. - name: POD_NAMESPACE
    176. valueFrom:
    177. fieldRef:
    178. fieldPath: metadata.namespace
    179. - name: EVENT_QUEUE_DEPTH
    180. value: "5000"
    181. volumeMounts:
    182. - name: run
    183. mountPath: /run/flannel
    184. - name: flannel-cfg
    185. mountPath: /etc/kube-flannel/
    186. - name: xtables-lock
    187. mountPath: /run/xtables.lock
    188. volumes:
    189. - name: run
    190. hostPath:
    191. path: /run/flannel
    192. - name: cni-plugin
    193. hostPath:
    194. path: /opt/cni/bin
    195. - name: cni
    196. hostPath:
    197. path: /etc/cni/net.d
    198. - name: flannel-cfg
    199. configMap:
    200. name: kube-flannel-cfg
    201. - name: xtables-lock
    202. hostPath:
    203. path: /run/xtables.lock
    204. type: FileOrCreate

     部署flannel

    1. [root@k8s-master ~]# kubectl apply -f kube-flannel.yml
    2. Warning: policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
    3. podsecuritypolicy.policy/psp.flannel.unprivileged created
    4. clusterrole.rbac.authorization.k8s.io/flannel created
    5. clusterrolebinding.rbac.authorization.k8s.io/flannel created
    6. serviceaccount/flannel created
    7. configmap/kube-flannel-cfg created
    8. daemonset.apps/kube-flannel-ds created

     查看集群状态(状态为Ready就代表k8s部署成功)

    1. [root@k8s-master ~]# kubectl get nodes
    2. NAME STATUS ROLES AGE VERSION
    3. k8s-master Ready control-plane,master 21m v1.23.6
    4. k8s-node1 Ready 20m v1.23.6
    5. k8s-node2 Ready 20m v1.23.6
    6. k8s-node3 Ready 20m v1.23.6

    查看各个节点详细信息

    1. [root@k8s-master ~]# kubectl get pod -n kube-system
    2. NAME READY STATUS RESTARTS AGE
    3. coredns-6d8c4cb4d-92g7b 1/1 Running 0 20m
    4. coredns-6d8c4cb4d-kl4q5 1/1 Running 0 20m
    5. etcd-k8s-master 1/1 Running 0 20m
    6. kube-apiserver-k8s-master 1/1 Running 0 20m
    7. kube-controller-manager-k8s-master 1/1 Running 0 20m
    8. kube-proxy-422b5 1/1 Running 0 19m
    9. kube-proxy-6qpcz 1/1 Running 0 19m
    10. kube-proxy-ggnnt 1/1 Running 0 20m
    11. kube-proxy-vjcnc 1/1 Running 0 19m
    12. kube-scheduler-k8s-master 1/1 Running 0 20m

    查看k8s里的命名空间有哪些(k8s自己创建的) 

    1. [root@k8s-master ~]# kubectl get ns
    2. NAME STATUS AGE
    3. default Active 22m
    4. kube-flannel Active 10m
    5. kube-node-lease Active 22m
    6. kube-public Active 22m
    7. kube-system Active 22m

    查看pod运行在哪个node上,

    1. [root@k8s-master ~]# kubectl get pod -n kube-flannel
    2. NAME READY STATUS RESTARTS AGE
    3. kube-flannel-ds-c7crw 1/1 Running 0 29m
    4. kube-flannel-ds-pr5pr 1/1 Running 0 29m
    5. kube-flannel-ds-rphnc 1/1 Running 0 29m
    6. kube-flannel-ds-v8rxz 1/1 Running 0 29m
    7. [root@k8s-master ~]# kubectl get pod -n kube-flannel -o wide
    8. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    9. kube-flannel-ds-c7crw 1/1 Running 0 29m 192.168.44.211 k8s-node1
    10. kube-flannel-ds-pr5pr 1/1 Running 0 29m 192.168.44.212 k8s-node2
    11. kube-flannel-ds-rphnc 1/1 Running 0 29m 192.168.44.210 k8s-master
    12. kube-flannel-ds-v8rxz 1/1 Running 0 29m 192.168.44.213 k8s-node3

    #############################################################################

  • 相关阅读:
    并发与并行
    随手写写(二)
    网络协议之:Domain name service DNS详解
    Java简单实现图片上传与下载
    最小二乘法
    使用Docker快速部署Flink分布式集群
    说下 MySQL 中的锁
    .Net CLR
    CSS 基础知识 属性
    maven与Jenkins
  • 原文地址:https://blog.csdn.net/qq_48391148/article/details/127017827