0
点赞
收藏
分享

微信扫一扫

mac上kubeadmin安装k8s(完整)

1.安装virtualBox

这个自行百度,安装好后,配置一下

这里我一点开,就这样,没有修改。

mac上kubeadmin安装k8s(完整)_kubeadm

2.vagrant安装虚拟机

2.1.安装vagrant

dz0400819@MacBook-Pro  ~  brew install vagrant

2.2.vagrant创建虚拟机

这里安装的是ubuntu20.04,如果想要其他版本,可以到https://app.vagrantup.com/ubuntu这里找

创建虚拟机
~/Desktop/docker/host2  vagrant init ubuntu/focal64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

启动虚拟机
~/Desktop/docker/host2  vagrant up

进入虚拟机
~/Desktop/docker/host2  vagrant ssh

2.3.内存至少为2G,少了报错

mac上kubeadmin安装k8s(完整)_kubeadm_02

3.安装docker

3.1.安装docker

安装docker
root@ubuntu-focal:~# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

3.2.查看docker的cgroup driver

Cgroup Driver: cgroupfs

root@ubuntu-focal:~# 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: 0
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: 5.4.0-96-generic
Operating System: Ubuntu 20.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.937GiB
Name: ubuntu-focal
ID: QK46:H3FX:EQIZ:QGHG:OLKZ:T3ID:QA65:LXNC:BRXR:HVUK:RCOQ:LDLO
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

WARNING: No swap limit support

3.3修改docker的cgroup driver

修改为systemd,要和kubelet的cgroup driver保持一致,不一致kubelet启动不了。

kubelet的1.22.2版本的cgroup driver是systemd,哈哈,因为坑我已经踩过一遍了。

root@ubuntu-focal:~# vim /etc/docker/daemon.json
root@ubuntu-focal:~# cat /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}

3.4启动docker并查看状态

启动后最好在docker info查看下cgroup driver是不是systemd

root@ubuntu-focal:~# service docker start
root@ubuntu-focal:~# service docker status
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-01-29 11:27:54 UTC; 3min 28s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 721 (dockerd)
Tasks: 8
Memory: 107.7M
CGroup: /system.slice/docker.service
└─721 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.271733866Z" level=warning msg="Your kernel does not support CPU realtime scheduler"
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.271869462Z" level=warning msg="Your kernel does not support cgroup blkio weight"
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.272000492Z" level=warning msg="Your kernel does not support cgroup blkio weight_device"
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.277560109Z" level=info msg="Loading containers: start."
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.948408290Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be>
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.139527485Z" level=info msg="Loading containers: done."
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.413437051Z" level=info msg="Docker daemon" commit=459d0df graphdriver(s)=overlay2 version=20.10.12
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.415677294Z" level=info msg="Daemon has completed initialization"
Jan 29 11:27:54 ubuntu-focal systemd[1]: Started Docker Application Container Engine.
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.503854906Z" level=info msg="API listen on /run/docker.sock"

4.Letting iptables see bridged traffic

$ cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

$ sudo sysctl --system

5.安装相关软件

5.1安装net-tools

因为要查看虚拟机的网络

root@ubuntu-focal:~# ifconfig

Command 'ifconfig' not found, but can be installed with:

apt install net-tools

root@ubuntu-focal:~# apt-get update
root@ubuntu-focal:~# apt install net-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 196 kB of archives.
After this operation, 864 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Fetched 196 kB in 3s (61.0 kB/s)
Selecting previously unselected package net-tools.
(Reading database ... 63485 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...


5.2Update the apt package index and install packages needed to use the Kubernetes apt repository:

root@ubuntu-focal:~# apt-get update
Hit:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done


root@ubuntu-focal:~# apt-get install -y apt-transport-https ca-certificates curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20210119~20.04.2).
curl is already the newest version (7.68.0-1ubuntu2.7).
apt-transport-https is already the newest version (2.0.6).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

5.3Install kubeadm

root@ubuntu-focal:~# curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
OK

5.4Add the Kubernetes apt repository

$ sudo tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF

5.5安装kubelet

更新apt package index

更新apt package index
root@ubuntu-focal:~# apt-get update

查看kubelet有哪些版本

root@ubuntu-focal:~# apt-cache policy kubelet

安装kubelet 1.22.2

因为k8s集群就是安装的这个版本,版本要相同,都则会报错

root@ubuntu-focal:~# apt-get install kubelet=1.22.2-00
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
conntrack ebtables kubernetes-cni socat
Suggested packages:
nftables
The following NEW packages will be installed:
conntrack ebtables kubelet kubernetes-cni socat
0 upgraded, 5 newly installed, 0 to remove and 4 not upgraded.
Need to get 47.3 MB of archives.
After this operation, 227 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubernetes-cni amd64 0.8.7-00 [25.0 MB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 conntrack amd64 1:1.4.5-2 [30.3 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 ebtables amd64 2.0.11-3build1 [80.3 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 socat amd64 1.7.3.3-2 [323 kB]
Get:5 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubelet amd64 1.22.2-00 [21.9 MB]
Fetched 47.3 MB in 6s (7442 kB/s)
Selecting previously unselected package conntrack.
(Reading database ... 63534 files and directories currently installed.)
Preparing to unpack .../conntrack_1%3a1.4.5-2_amd64.deb ...
Unpacking conntrack (1:1.4.5-2) ...
Selecting previously unselected package ebtables.
Preparing to unpack .../ebtables_2.0.11-3build1_amd64.deb ...
Unpacking ebtables (2.0.11-3build1) ...
Selecting previously unselected package kubernetes-cni.
Preparing to unpack .../kubernetes-cni_0.8.7-00_amd64.deb ...
Unpacking kubernetes-cni (0.8.7-00) ...
Selecting previously unselected package socat.
Preparing to unpack .../socat_1.7.3.3-2_amd64.deb ...
Unpacking socat (1.7.3.3-2) ...
Selecting previously unselected package kubelet.
Preparing to unpack .../kubelet_1.22.2-00_amd64.deb ...
Unpacking kubelet (1.22.2-00) ...
Setting up conntrack (1:1.4.5-2) ...
Setting up ebtables (2.0.11-3build1) ...
Setting up socat (1.7.3.3-2) ...
Setting up kubernetes-cni (0.8.7-00) ...
Setting up kubelet (1.22.2-00) ...
Created symlink /etc/systemd/system/multi-user.target.wants/kubelet.service → /lib/systemd/system/kubelet.service.
Processing triggers for man-db (2.9.1-1) ...

安装固定版本的kubeadm 和kubectl

root@ubuntu-focal:~# apt-get install -y kubeadm=1.22.2-00 kubectl=1.22.2-00
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
cri-tools
The following NEW packages will be installed:
cri-tools kubeadm kubectl
0 upgraded, 3 newly installed, 0 to remove and 5 not upgraded.
Need to get 28.9 MB of archives.
After this operation, 123 MB of additional disk space will be used.
Get:1 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 cri-tools amd64 1.19.0-00 [11.2 MB]
Get:2 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubectl amd64 1.22.2-00 [9038 kB]
Get:3 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubeadm amd64 1.22.2-00 [8718 kB]
Fetched 28.9 MB in 4s (7822 kB/s)
Selecting previously unselected package cri-tools.
(Reading database ... 63622 files and directories currently installed.)
Preparing to unpack .../cri-tools_1.19.0-00_amd64.deb ...
Unpacking cri-tools (1.19.0-00) ...
Selecting previously unselected package kubectl.
Preparing to unpack .../kubectl_1.22.2-00_amd64.deb ...
Unpacking kubectl (1.22.2-00) ...
Selecting previously unselected package kubeadm.
Preparing to unpack .../kubeadm_1.22.2-00_amd64.deb ...
Unpacking kubeadm (1.22.2-00) ...
Setting up kubectl (1.22.2-00) ...
Setting up cri-tools (1.19.0-00) ...
Setting up kubeadm (1.22.2-00) ...

apt-mark hold

root@ubuntu-focal:~# apt-mark hold kubelet kubeadm kubectl
kubelet was already set on hold.
kubeadm set on hold.
kubectl set on hold.

5.6kubeadm init

查看虚拟机IP:10.0.2.15

root@ubuntu-focal:~# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:73:64:74:d0 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::cd:1cff:fe36:98 prefixlen 64 scopeid 0x20<link>
ether 02:cd:1c:36:00:98 txqueuelen 1000 (Ethernet)
RX packets 93667 bytes 134751544 (134.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22209 bytes 1469134 (1.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 140 bytes 16230 (16.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 140 bytes 16230 (16.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

root@ubuntu-focal:~#

初始化

root@ubuntu-focal:~# kubeadm init  --image-repository registry.aliyuncs.com/google_containers  --kubernetes-version v1.22.2  --pod-network-cidr=192.168.0.0/16  --apiserver-advertise-address=10.0.2.15
[init] Using Kubernetes version: v1.22.2
[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] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local ubuntu-focal] and IPs [10.96.0.1 10.0.2.15]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost ubuntu-focal] and IPs [10.0.2.15 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost ubuntu-focal] and IPs [10.0.2.15 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[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 8.506213 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.22" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node ubuntu-focal 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 ubuntu-focal as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: qgiq2m.cjekeq2gq8ngibvn
[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 10.0.2.15:6443 --token qgiq2m.cjekeq2gq8ngibvn \
--discovery-token-ca-cert-hash sha256:bc219ff9548e537de3ef7ebf41e548389e2adadb0f951e18a347515d9237b898
root@ubuntu-focal:~#

查看kubelet的cgroup driver

我这里在测试的时候,只有init后才能查看,你可以提前试试看

cgroupDriver: systemd

root@ubuntu-focal:~# systemctl show --property=Environment kubelet | cat
Environment=[unprintable] KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml


root@ubuntu-focal:~# cat /var/lib/kubelet/config.yaml
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
anonymous:
enabled: false
webhook:
cacheTTL: 0s
enabled: true
x509:
clientCAFile: /etc/kubernetes/pki/ca.crt
authorization:
mode: Webhook
webhook:
cacheAuthorizedTTL: 0s
cacheUnauthorizedTTL: 0s
cgroupDriver: systemd
clusterDNS:
- 10.96.0.10
clusterDomain: cluster.local
cpuManagerReconcilePeriod: 0s
evictionPressureTransitionPeriod: 0s
fileCheckFrequency: 0s
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 0s
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging: {}
memorySwap: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
resolvConf: /run/systemd/resolve/resolv.conf
rotateCertificates: true
runtimeRequestTimeout: 0s
shutdownGracePeriod: 0s
shutdownGracePeriodCriticalPods: 0s
staticPodPath: /etc/kubernetes/manifests
streamingConnectionIdleTimeout: 0s
syncFrequency: 0s
volumeStatsAggPeriod: 0s

Copy kubeconfig

root@ubuntu-focal:~# mkdir -p $HOME/.kube
root@ubuntu-focal:~# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
root@ubuntu-focal:~# chown $(id -u):$(id -g) $HOME/.kube/config

查看集群状态

root@ubuntu-focal:~# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-7f6cbbb7b8-gxwfp 0/1 Pending 0 4m6s
coredns-7f6cbbb7b8-twcf6 0/1 Pending 0 4m6s
etcd-ubuntu-focal 1/1 Running 2 4m23s
kube-apiserver-ubuntu-focal 1/1 Running 2 4m21s
kube-controller-manager-ubuntu-focal 1/1 Running 3 4m21s
kube-proxy-g9tnm 1/1 Running 0 4m7s
kube-scheduler-ubuntu-focal 1/1 Running 3 4m21s

5.7Install calico cni plugin

$ kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
$ kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml

安装好后,查看pod

root@ubuntu-focal:~# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
calico-system calico-kube-controllers-666bb9949-qm9ls 0/1 ContainerCreating 0 5m45s
calico-system calico-node-hlpzh 0/1 PodInitializing 0 5m45s
calico-system calico-typha-769645cd77-xhr28 1/1 Running 0 5m45s
kube-system coredns-7f6cbbb7b8-gxwfp 0/1 ContainerCreating 0 15m
kube-system coredns-7f6cbbb7b8-twcf6 0/1 ContainerCreating 0 15m
kube-system etcd-ubuntu-focal 1/1 Running 2 16m
kube-system kube-apiserver-ubuntu-focal 1/1 Running 2 16m
kube-system kube-controller-manager-ubuntu-focal 1/1 Running 3 16m
kube-system kube-proxy-g9tnm 1/1 Running 0 16m
kube-system kube-scheduler-ubuntu-focal 1/1 Running 3 16m
tigera-operator tigera-operator-c4b9549c7-ls2g5 1/1 Running 0 8m37s
root@ubuntu-focal:~#

没有网络插件,coreDns启动不了,报错信息如下

network plugin is not ready: cni config uninitialized

root@ubuntu-focal:~# kubectl describe pod coredns-7f6cbbb7b8-gxwfp -n kube-system
Name: coredns-7f6cbbb7b8-gxwfp
Namespace: kube-system
Priority: 2000000000
Priority Class Name: system-cluster-critical
Node: ubuntu-focal/10.0.2.15
Start Time: Sat, 29 Jan 2022 12:23:13 +0000
Labels: k8s-app=kube-dns
pod-template-hash=7f6cbbb7b8
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: ReplicaSet/coredns-7f6cbbb7b8
Containers:
coredns:
Container ID:
Image: registry.aliyuncs.com/google_containers/coredns:v1.8.4
Image ID:
Ports: 53/UDP, 53/TCP, 9153/TCP
Host Ports: 0/UDP, 0/TCP, 0/TCP
Args:
-conf
/etc/coredns/Corefile
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Limits:
memory: 170Mi
Requests:
cpu: 100m
memory: 70Mi
Liveness: http-get http://:8080/health delay=60s timeout=5s period=10s #success=1 #failure=5
Readiness: http-get http://:8181/ready delay=0s timeout=1s period=10s #success=1 #failure=3
Environment: <none>
Mounts:
/etc/coredns from config-volume (ro)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-nkm28 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
config-volume:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: coredns
Optional: false
kube-api-access-nkm28:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: Burstable
Node-Selectors: kubernetes.io/os=linux
Tolerations: CriticalAddonsOnly op=Exists
node-role.kubernetes.io/control-plane:NoSchedule
node-role.kubernetes.io/master:NoSchedule
node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 4m17s (x9 over 12m) default-scheduler 0/1 nodes are available: 1 node(s) had taint {node.kubernetes.io/not-ready: }, that the pod didn't tolerate.
Normal Scheduled 3m38s default-scheduler Successfully assigned kube-system/coredns-7f6cbbb7b8-gxwfp to ubuntu-focal
Warning NetworkNotReady 2m50s (x25 over 3m38s) kubelet network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized

5.8取消master节点污点

上面coreDns  pending,就是因为master节点的污点

查看有哪些污点

root@ubuntu-focal:~# kubectl get node
NAME STATUS ROLES AGE VERSION
ubuntu-focal NotReady control-plane,master 5m7s v1.22.2
root@ubuntu-focal:~# kubectl describe node ubuntu-focal
Name: ubuntu-focal
Roles: control-plane,master
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/arch=amd64
kubernetes.io/hostname=ubuntu-focal
kubernetes.io/os=linux
node-role.kubernetes.io/control-plane=
node-role.kubernetes.io/master=
node.kubernetes.io/exclude-from-external-load-balancers=
Annotations: kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
node.alpha.kubernetes.io/ttl: 0
volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp: Sat, 29 Jan 2022 12:13:59 +0000
Taints: node-role.kubernetes.io/master:NoSchedule
node.kubernetes.io/not-ready:NoSchedule

删除污点

root@ubuntu-focal:~# kubectl taint node ubuntu-focal node-role.kubernetes.io/master:NoSchedule-
node/ubuntu-focal untainted
root@ubuntu-focal:~# kubectl taint node ubuntu-focal node.kubernetes.io/not-ready:NoSchedule-
node/ubuntu-focal untainted

查看集群状态

root@ubuntu-focal:~# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-7f6cbbb7b8-gxwfp 0/1 ContainerCreating 0 10m
coredns-7f6cbbb7b8-twcf6 0/1 ContainerCreating 0 10m
etcd-ubuntu-focal 1/1 Running 2 11m
kube-apiserver-ubuntu-focal 1/1 Running 2 11m
kube-controller-manager-ubuntu-focal 1/1 Running 3 11m
kube-proxy-g9tnm 1/1 Running 0 10m
kube-scheduler-ubuntu-focal 1/1 Running 3 11m

过一会,等到calico的pod运行成功,就全都没问题了。

root@ubuntu-focal:~# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
calico-system calico-kube-controllers-666bb9949-qm9ls 0/1 ContainerCreating 0 6m50s
calico-system calico-node-hlpzh 1/1 Running 0 6m50s
calico-system calico-typha-769645cd77-xhr28 1/1 Running 0 6m50s
kube-system coredns-7f6cbbb7b8-gxwfp 1/1 Running 0 17m
kube-system coredns-7f6cbbb7b8-twcf6 1/1 Running 0 17m
kube-system etcd-ubuntu-focal 1/1 Running 2 17m
kube-system kube-apiserver-ubuntu-focal 1/1 Running 2 17m
kube-system kube-controller-manager-ubuntu-focal 1/1 Running 3 17m
kube-system kube-proxy-g9tnm 1/1 Running 0 17m
kube-system kube-scheduler-ubuntu-focal 1/1 Running 3 17m
tigera-operator tigera-operator-c4b9549c7-ls2g5 1/1 Running 0 9m42s
root@ubuntu-focal:~#
举报

相关推荐

0 条评论