一.环境准备

配置: 一台虚机,4C16G100G

系统: ubuntu22.04

部署方式: snap部署

服务:microk8s

二.部署前环境操作

三.microk8s部署

方式一

1.在线部署

snap install microk8s --classic

查看服务状态

microk8s status

microk8s inspect

root@paas-test-ubuntu:~# microk8s status
microk8s is not running. Use microk8s inspect for a deeper inspection.
root@paas-test-ubuntu:~# microk8s inspect
Inspecting system
Inspecting Certificates
Inspecting services
  Service snap.microk8s.daemon-cluster-agent is running
  Service snap.microk8s.daemon-containerd is running
  Service snap.microk8s.daemon-kubelite is running
  Service snap.microk8s.daemon-k8s-dqlite is running
  Service snap.microk8s.daemon-apiserver-kicker is running
  Copy service arguments to the final report tarball
Inspecting AppArmor configuration
Gathering system information
  Copy processes list to the final report tarball
  Copy disk usage information to the final report tarball
  Copy memory usage information to the final report tarball
  Copy server uptime to the final report tarball
  Copy openSSL information to the final report tarball
  Copy snap list to the final report tarball
  Copy VM name (or none) to the final report tarball
  Copy current linux distribution to the final report tarball
  Copy asnycio usage and limits to the final report tarball
  Copy inotify max_user_instances and max_user_watches to the final report tarball
  Copy network configuration to the final report tarball
Inspecting kubernetes cluster
  Inspect kubernetes cluster
Inspecting dqlite
  Inspect dqlite
cp: cannot stat '/var/snap/microk8s/7449/var/kubernetes/backend/localnode.yaml': No such file or directory

Building the report tarball
  Report tarball is at /var/snap/microk8s/7449/inspection-report-20241227_160657.tar.gz
View Code

kubectl get pod -A 

 查看日志:

journalctl  -f -u snap.microk8s.daemon-containerd.service

镜像拉不动导致

root@paas-test-ubuntu:~# journalctl  -f -u snap.microk8s.daemon-containerd.service
Dec 27 16:08:32 paas-test-ubuntu microk8s.daemon-containerd[626668]: time="2024-12-27T16:08:32.278317063+08:00" level=info msg="RunPodSandbox for &PodSandboxMetadata{Name:calico-node-2v9tn,Uid:5fda4789-454b-4659-b4be-9d3be79cd06d,Namespace:kube-system,Attempt:0,}"
Dec 27 16:09:02 paas-test-ubuntu microk8s.daemon-containerd[626668]: time="2024-12-27T16:09:02.794789651+08:00" level=info msg="trying next host" error="failed to do request: Head \"https://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.7\": dial tcp 142.250.107.82:443: i/o timeout" host=registry.k8s.io
Dec 27 16:09:02 paas-test-ubuntu microk8s.daemon-containerd[626668]: time="2024-12-27T16:09:02.796272813+08:00" level=error msg="RunPodSandbox for &PodSandboxMetadata{Name:calico-node-2v9tn,Uid:5fda4789-454b-4659-b4be-9d3be79cd06d,Namespace:kube-system,Attempt:0,} failed, error" error="rpc error: code = DeadlineExceeded desc = failed to get sandbox image \"registry.k8s.io/pause:3.7\": failed to pull image \"registry.k8s.io/pause:3.7\": failed to pull and unpack image \"registry.k8s.io/pause:3.7\": failed to resolve reference \"registry.k8s.io/pause:3.7\": failed to do request: Head \"https://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.7\": dial tcp 142.250.107.82:443: i/o timeout"
Dec 27 16:09:16 paas-test-ubuntu microk8s.daemon-containerd[626668]: time="2024-12-27T16:09:16.279977258+08:00" level=info msg="RunPodSandbox for &PodSandboxMetadata{Name:calico-node-2v9tn,Uid:5fda4789-454b-4659-b4be-9d3be79cd06d,Namespace:kube-system,Attempt:0,}"
Dec 27 16:09:46 paas-test-ubuntu microk8s.daemon-containerd[626668]: time="2024-12-27T16:09:46.774197381+08:00" level=info msg="trying next host" error="failed to do request: Head \"https://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.7\": dial tcp 142.250.107.82:443: i/o timeout" host=registry.k8s.io
Dec 27 16:09:46 paas-test-ubuntu microk8s.daemon-containerd[626668]: time="2024-12-27T16:09:46.774954948+08:00" level=error msg="RunPodSandbox for &PodSandboxMetadata{Name:calico-node-2v9tn,Uid:5fda4789-454b-4659-b4be-9d3be79cd06d,Namespace:kube-system,Attempt:0,} failed, error" error="rpc error: code = DeadlineExceeded desc = failed to get sandbox image \"registry.k8s.io/pause:3.7\": failed to pull image \"registry.k8s.io/pause:3.7\": failed to pull and unpack image \"registry.k8s.io/pause:3.7\": failed to resolve reference \"registry.k8s.io/pause:3.7\": failed to do request: Head \"https://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.7\": dial tcp 142.250.107.82:443: i/o timeout"
Dec 27 16:10:01 paas-test-ubuntu microk8s.daemon-containerd[626668]: time="2024-12-27T16:10:01.279052552+08:00" level=info msg="RunPodSandbox for &PodSandboxMetadata{Name:calico-node-2v9tn,Uid:5fda4789-454b-4659-b4be-9d3be79cd06d,Namespace:kube-system,Attempt:0,}"
View Code

解决办法:

#处理pause镜像

修改: /var/snap/microk8s/current/args/containerd-template.toml 

sandbox_image = "registry.cn-hangzhou.aliyuncs.com/mytest_docker123/pause:3.9"

#处理calico镜像

修改:/snap/microk8s/current/upgrade-scripts/000-switch-to-calico/resources/calico.yaml