kubeadm init --config=kubeadm.yaml # [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 [k8s-master-1 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local newcluster.k8s] and IPs [10.96.0.1 10.10.107.220] ...... # [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: # - 拷贝 kubeconfig 文件到当前用户的根目录,完毕后即可采用kubectl进行查看管理k8s集群。 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/
# You can now join any number of control-plane nodes by copying certificate authorities # and service account keys on each node and then running the following as root: # 从Master节点执行 kubeadm join newcluster.k8s:6443 --token abcdef.0123456789abcdef \ --discovery-token-ca-cert-hash sha256:d57743fa8657a959e6f96ea1b2d16ce32c315a2a6dc080a65a2b0fc8849bfbd4 \ --control-plane
# Then you can join any number of worker nodes by running the following on each as root: # 工作节点执行 kubeadm join newcluster.k8s:6443 --token abcdef.0123456789abcdef \ --discovery-token-ca-cert-hash sha256:d57743fa8657a959e6f96ea1b2d16ce32c315a2a6dc080a65a2b0fc8849bfbd4
# - 安装 Pod 网络前节点的状态为NotReady ~/k8s# kubectl get node NAME STATUS ROLES AGE VERSION k8s-master-1 NotReady control-plane,master 11m v1.20.8 k8s-node-1 NotReady <none> 4m19s v1.20.8
# - 自定义更改calico插件的地址池。 # The default IPv4 pool to create on startup if none exists. Pod IPs will be chosen from this range. Changing this value after installation will have no effect. This should fall within `--cluster-cidr`. vim calico.yaml - name: CALICO_IPV4POOL_CIDR value: "192.168.0.0/16"
# - 部署 calico 网络插件 kubectl apply -f calico.yaml
# - 部署后查看kube-system中和网络相关的pod的运行状态,一般的状态回从Pending -> Init -> ContainerCreate -> Running过程转变。 ~/k8s# kubectl get pod -n kube-system NAME READY STATUS RESTARTS AGE calico-kube-controllers-77dd468cdb-2lchv 0/1 Pending 0 18s calico-node-pz9qx 0/1 Init:0/3 0 18s calico-node-zvst7 0/1 Init:0/3 0 18s coredns-54d67798b7-78n5j 0/1 Pending 0 15m coredns-54d67798b7-z9c8f 0/1 Pending 0 15m
# - 等待几分钟后calico插件相关Pod已成功运行 ~/k8s# kubectl get pod -n kube-system NAME READY STATUS RESTARTS AGE calico-kube-controllers-77dd468cdb-2lchv 1/1 Running 0 2m18s calico-node-pz9qx 1/1 Running 0 2m18s calico-node-zvst7 1/1 Running 0 2m18s coredns-54d67798b7-78n5j 1/1 Running 0 17m coredns-54d67798b7-z9c8f 1/1 Running 0 17m
# - 同时可以看到其Node节点的状态已变为Ready,至此calico网络插件安装部署已完毕。 ~/k8s# kubectl get node NAME STATUS ROLES AGE VERSION k8s-master-1 Ready control-plane,master 17m v1.20.8 k8s-node-1 Ready <none> 10m v1.20.8
~/k8s/containerd# kubectl -n weiyigeek get pod # NAME READY STATUS RESTARTS AGE # web-deploy-99fbb677d-jbbwk 1/1 Running 0 48s # web-deploy-99fbb677d-md5z9 1/1 Running 0 51s
~/k8s/containerd# kubectl -n weiyigeek get svc # NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE # nginx-service NodePort 10.105.172.104 <none> 80:30000/TCP 59m
$ ctr container rm busybox ERRO[0000] failed to delete container "busybox" error="container \"busybox\" in namespace \"default\": not found" ctr: container "busybox"in namespace "default": not found
错误原因: 由于 default 的默认名称空间内无busybox所以删除时报错.
解决办法: 查看有那些名称空间ctr namespace ls
问题3.使用ctr拉取镜像时报INFO[0001] trying next host error="failed to authorize: failed to fetch anonymous token:错误
错误信息:
1 2 3 4 5
$ ctr -n k8s.io images pull docker.io/library/busybox:latest # docker.io/library/busybox:latest: resolving |--------------------------------------| # elapsed: 1.1 s total: 0.0 B (0.0 B/s) # INFO[0001] trying next host error="failed to authorize: failed to fetch anonymous token: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fbusybox%3Apull&service=registry.docker.io: read tcp 10.10.107.220:62946->107.23.149.57:443: read: connection reset by peer" host=registry-1.docker.io # ctr: failed to resolve reference "docker.io/library/busybox:latest": failed to authorize: failed to fetch anonymous token: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fbusybox%3Apull&service=registry.docker.io: read tcp 10.10.107.220:62946->107.23.149.57:443: read: connection reset by peer
错误信息: Unfortunately, an error has occurred: timed out waiting for the condition
错误排查:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# - 此错误可能由以下原因引起: - The kubelet is not running - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
# - 集群 pod 排错常用命令指南 kubectl get pod <pod-name> -o yaml # 查看 Pod 的配置是否正确 kubectl describe pod <pod-name> # 查看 Pod 的事件 kubectl logs <pod-name> [-c <container-name>] # 查看容器日志
实际案例:
1 2 3 4 5 6 7
journalctl -xeu kubelet # Jul 06 22:15:29 k8s-master-1 kubelet[11333]: E0706 22:15:29.108499 11333 kubelet.go:2183] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized # Jul 06 22:15:29 k8s-master-1 kubelet[11333]: E0706 22:15:29.206203 11333 kubelet.go:2263] node "k8s-master-1" not found # Jul 06 22:15:29 k8s-master-1 kubelet[11333]: E0706 22:15:29.208552 11333 remote_runtime.go:116] RunPodSandbox from runtime service failed: rpc error: code = Unknown desc = failed to get sandbox image "k8s.gcr.io/pause:3.2": failed to pull image "> # Jul 06 22:15:29 k8s-master-1 kubelet[11333]: E0706 22:15:29.208609 11333 kuberuntime_sandbox.go:70] CreatePodSandbox for pod "kube-controller-manager-k8s-master-1_kube-system(d1d11a3cb97124022c9d85b070508dfa)" failed: rpc error: code = Unknown de> # Jul 06 22:15:29 k8s-master-1 kubelet[11333]: E0706 22:15:29.208621 11333 kuberuntime_manager.go:755] createPodSandbox for pod "kube-controller-manager-k8s-master-1_kube-system(d1d11a3cb97124022c9d85b070508dfa)" failed: rpc error: code = Unknown d> # Jul 06 22:15:29 k8s-master-1 kubelet[11333]: E0706 22:15:29.208682 11333 pod_workers.go:191] Error syncing pod d1d11a3cb97124022c9d85b070508dfa ("kube-controller-manager-k8s-master-1_kube-system(d1d11a3cb97124022c9d85b070508dfa)"), skipping: fail>
3.创建Pod时报Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container.错误
错误信息:
1
Warning FailedCreatePodSandBox 89s kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container "1c97ad2710e2939c0591477f9d6dde8e0d7d31b3fbc138a7fa38aaa657566a9a" network for pod "coredns-7f89b7bc75-qg924": networkPlugin cni failed to set up pod "coredns-7f89b7bc75-qg924_kube-system" network: error getting ClusterInformation: Get "https://[10.96.0.1]:443/apis/crd.projectcalico.org/v1/clusterinformations/default": x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error"while trying to verify candidate authority certificate "kubernetes"), failed to clean up sandbox container "1c97ad2710e2939c0591477f9d6dde8e0d7d31b3fbc138a7fa38aaa657566a9a" network for pod "coredns-7f89b7bc75-qg924": networkPlugin cni failed to teardown pod "coredns-7f89b7bc75-qg924_kube-system" network: error getting ClusterInformation: Get "https://[10.96.0.1]:443/apis/crd.projectcalico.org/v1/clusterinformations/default": x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error"while trying to verify candidate authority certificate "kubernetes")]
表现状态: coredns无法运行
1 2 3 4
$ kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-7f89b7bc75-jzs26 0/1 ContainerCreating 0 63s coredns-7f89b7bc75-qg924 0/1 ContainerCreating 0 63s
解决办法: 更改calico.yaml
1 2 3 4 5 6 7 8 9 10 11 12
$ vim calico.yaml # Cluster type to identify the deployment type - name: CLUSTER_TYPE value: "k8s,bgp" # 下方熙增新增 - name: IP_AUTODETECTION_METHOD value: "interface=ens192" # ens192为本地网卡名字
$ cat /boot/config-`uname -r` | grep CGROUP CONFIG_CGROUPS=y CONFIG_BLK_CGROUP=y CONFIG_CGROUP_WRITEBACK=y CONFIG_CGROUP_SCHED=y CONFIG_CGROUP_PIDS=y CONFIG_CGROUP_RDMA=y CONFIG_CGROUP_FREEZER=y CONFIG_CGROUP_HUGETLB=y CONFIG_CGROUP_DEVICE=y CONFIG_CGROUP_CPUACCT=y CONFIG_CGROUP_PERF=y CONFIG_CGROUP_BPF=y # CONFIG_CGROUP_DEBUG is not set CONFIG_SOCK_CGROUP_DATA=y # CONFIG_BLK_CGROUP_IOLATENCY is not set CONFIG_BLK_CGROUP_IOCOST=y # CONFIG_BFQ_CGROUP_DEBUG is not set CONFIG_NETFILTER_XT_MATCH_CGROUP=m CONFIG_NET_CLS_CGROUP=m CONFIG_CGROUP_NET_PRIO=y CONFIG_CGROUP_NET_CLASSID=y
5.使用Kubectl查看工作节点时发现节点状态为NotReady,并报出Network plugin returns error: cni plugin not initialized错误解决办法.
方式1.请访问本博主的B站【WeiyiGeek】首页关注UP主, 将自动随机获取解锁验证码。
Method 2.Please visit 【My Twitter】. There is an article verification code in the homepage.
方式3.扫一扫下方二维码,关注本站官方公众号
回复:验证码
将获取解锁(有效期7天)本站所有技术文章哟!