环境:

kubeadm v1.22.2

kubeadm init所需镜像:

“k8s.gcr.io/kube-apiserver:v1.22.2”
k8s.gcr.io/kube-controller-manager:v1.22.2
k8s.gcr.io/kube-scheduler:v1.22.2
k8s.gcr.io/kube-proxy:v1.22.2
k8s.gcr.io/pause:3.5
k8s.gcr.io/etcd:3.5.0-0
k8s.gcr.io/coredns/coredns:v1.8.4
以上镜像位于国外,无法kubeadm init自动获取;需要手动pull
手动下载镜像后,执行kubeadm init还是会报错下载不到镜像,可以加上kubeadm init --ignore-preflight-errors=ImagePull忽略报错,例:

root@ubuntu:~# kubeadm init  --ignore-preflight-errors=ImagePull

或者指定使用阿里云镜像
运行kubeadm init时加上阿里云镜像的参数–image-repository=registry.aliyuncs.com/google_containers,如下:(版本改为自己需要的)

kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.22.2
如果还有问题,那可以用下面这个比较复杂的方法

从DockerHub的其它仓库拉取

kubeadm init运行成功之后,如果用普通用户启动集群,还需要运行以下命令:

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

如果是root用户运行,可以直接执行以下命令:

export KUBECONFIG=/etc/kubernetes/admin.conf

Installing a Pod network add-on

kubectl apply -f <add-on.yaml>报错:

root@ubuntu:~# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
The connection to the server raw.githubusercontent.com was refused - did you specify the right host or port?

关闭防火墙重试,还报错的话:
1、找到域名对应的ip地址
域名ip查询链接链接:http://ip.tool.chinaz.com/
在这里插入图片描述
/etc/hosts中添加主机ip映射信息

root@ubuntu:~# cat /etc/hosts
127.0.0.1	localhost
127.0.1.1	ubuntu
185.199.111.133 raw.githubusercontent.com

重新执行: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

root@ubuntu:~# iptables -F
root@ubuntu:~# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/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@ubuntu:~#

验证container network Interface是否创建成功:kubectl get pods --all-namespaces

root@ubuntu:~# kubectl get pods --all-namespaces
NAMESPACE     NAME                             READY   STATUS                  RESTARTS   AGE
kube-system   coredns-78fcd69978-7xq7t         0/1     ContainerCreating       0          168m
kube-system   coredns-78fcd69978-9l89j         0/1     ContainerCreating       0          168m
kube-system   etcd-ubuntu                      1/1     Running                 0          168m
kube-system   kube-apiserver-ubuntu            1/1     Running                 0          168m
kube-system   kube-controller-manager-ubuntu   1/1     Running                 0          168m
kube-system   kube-flannel-ds-q25kz            0/1     Init:ImagePullBackOff   0          9m16s
kube-system   kube-proxy-96qft                 1/1     Running                 0          168m
kube-system   kube-scheduler-ubuntu            1/1     Running                 0          168m
root@ubuntu:~# 

节点加入kubernete:

root@ubuntu:~# kubeadm join 192.168.184.136:6443 --token 4i8ydg.j9i8lc327b4sfq4u \
> --discovery-token-ca-cert-hash sha256:c1f0b70632a07038876383c25263526789062c1f874588c8ee44742c3846d24c 

报错:

[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
	[ERROR DirAvailable--etc-kubernetes-manifests]: /etc/kubernetes/manifests is not empty
	[ERROR FileAvailable--etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
	[ERROR Port-10250]: Port 10250 is in use
	[ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
[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

note: 默认kubernete不允许在主控节点上调度pod,如果是单节点测试学习kubenete,需要执行以下命令取消在控制结点上建pod的限制

root@ubuntu:~# kubectl taint nodes --all node-role.kubernetes.io/master-
node/ubuntu untainted
root@ubuntu:~# 
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐