k8s初始化及遇到问题

执行:kubeadm init --config=kubeadm.yaml --ignore-preflight-errors=SystemVerification

问题1:

[root@131 ~]# kubeadm init --config=kubeadm.yaml --ignore-preflight-errors=SystemVerification
[init] Using Kubernetes version: v1.27.0
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
	[ERROR CRI]: container runtime is not running: output: time="2023-07-17T22:05:28+08:00" level=fatal msg="validate service connection: CRI v1 runtime API is not implemented for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"
, error: exit status 1
	[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[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

解决方案:
注释掉kubeadm.yaml中criSocket

nodeRegistration:
#  criSocket: unix:///run/containerd/containerd.sock   #报的是这个错,但不知道为什么一直报这个地址的错
  imagePullPolicy: IfNotPresent
  name: xueshen131
  taints: null

问题2:

[root@131 ~]# kubeadm init --config=kubeadm.yaml --ignore-preflight-errors=SystemVerification
[init] Using Kubernetes version: v1.27.0
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
	[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[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

解决方案:

[root@131 ~]# modprobe br_netfilter 
[root@131 ~]# cat /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
[root@131 ~]# sysctl -p

解决后初始化成功

[root@131 ~]# kubeadm init --config=kubeadm.yaml --ignore-preflight-errors=SystemVerification
[init] Using Kubernetes version: v1.27.0
[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'
W0717 22:15:57.212269   64473 images.go:80] could not find officially supported version of etcd for Kubernetes v1.27.0, falling back to the nearest etcd version (3.5.7-0)
[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 xueshen131] and IPs [10.96.0.1 192.168.48.131]
[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 xueshen131] and IPs [192.168.48.131 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost xueshen131] and IPs [192.168.48.131 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"
W0717 22:18:43.285803   64473 images.go:80] could not find officially supported version of etcd for Kubernetes v1.27.0, falling back to the nearest etcd version (3.5.7-0)
[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 7.002588 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" 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 xueshen131 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node xueshen131 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: abcdef.0123456789abcdef
[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 192.168.48.131:6443 --token abcdef.0123456789abcdef \
	--discovery-token-ca-cert-hash sha256:7834da4d14dba1006db091025b4c25b725a423959021feb47a7356d719b9ff71 

服务器ip 服务器作用 服务器系统版本 服务器涉及软件
192.168.48.131 控制节点 Centos7.9 Docker-ce-1.23,containerd1.6.6,
kubelet-1.27.0,kubeadm-1.27.0, kubectl-1.27.0

192.168.48.130 工作节点 Centos7.9 Docker-ce-1.23,containerd1.6.6,
kubelet-1.27.0,kubeadm-1.27.0, kubectl-1.27.0

192.168.48.129 工作节点 Centos7.9 Docker-ce-1.23,containerd1.6.6,
kubelet-1.27.0,kubeadm-1.27.0, kubectl-1.27.0

1、需要再三个服务器上执行的yum

yum install -y yum-utils device-mapper-persistent-data lvm2 wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack ntpdate telnet
yum install -y docker-ce-cli-23.0.0
yum install  containerd.io-1.6.6 -y 

2、需要再三个节点上同时配置

(1)配置互相免密码登录,配置时间同步,关闭交换分区,关闭firewalld和selinux

(2)所需yum源这3个即可,阿里云,docekr和kubernetes

ll /etc/yum.repos.d/
总用量 12
-rw-r--r--  1 root root 2493 717 14:26 CentOS-Base.repo
-rw-r--r--. 1 root root 2081 628 15:08 docker-ce.repo
-rw-r--r--. 1 root root  129 628 15:09 kubernetes.repo

(3)配置文件修改和创建

cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://3vta0yzw.mirror.aliyuncs.com"]
}

3、在控制节点上单独的配置

/etc/containerd/config.toml

containerd config default > /etc/containerd/config.toml
vim  /etc/containerd/config.toml
SystemdCgroup = true
config_path = "/etc/containerd/certs.d"
#sandbox_image这块后面的数值是我k8s初始化的时候一直报错,我干脆把它提示建议的路径放上去了
sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9"

/etc/crictl.yaml

cat /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false

/etc/containerd/certs.d/docker.io/hosts.toml

mkdir -p /etc/containerd/certs.d/docker.io
cat /etc/containerd/certs.d/docker.io/hosts.toml 
[host."https://3vta0yzw.mirror.aliyuncs.com",host."https://registry.docker-cn.com"]
  capabilities = ["pull","push"]

kubeadm.yaml

kubeadm config print init-defaults > kubeadm.yaml
vim kubeadm.yaml
.....
advertiseAddress:#控制节点ip
......
nodeRegistration:
#  criSocket: unix:///run/containerd/containerd.sock  #k8s初始化这行报错了,注释后初始化成功
 imagePullPolicy: IfNotPresent
 name: #控制节点主机名
 ......
 imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers  #指定阿里云镜像仓库地址
 kubernetesVersion: #根据实际情况写 #k8s 版本
networking:
 dnsDomain: cluster.local
 podSubnet:  #指定 pod 网段

4、初始化k8s

重启需要的配置,看下状态status

systemctl enable kubelet
systemctl restart containerd.service
systemctl daemon-reload
systemctl restart docker

初始化(成功后的提示上面问题里有,太长了,我就不再复制了)

kubeadm init --config=kubeadm.yaml --ignore-preflight-errors=SystemVerification
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值