vim /etc/hosts 10.128.0.3 k8scp #<-- 新增这一行 127.0.0.1 localhost
创建并设置kebeadm config
1 2 3 4 5 6 7 8 9 10
apiVersion:kubeadm.k8s.io/v1beta3 kind:ClusterConfiguration # 推荐添加imageRepository 国内镜像进行初始化 imageRepository:"registry.cn-hangzhou.aliyuncs.com/google_containers"# <-- 国内镜像 kubernetesVersion:1.27.1#<-- Use the word stable for newest version controlPlaneEndpoint:"k8scp:6443"#<-- 使用我们填写到 /etc/hosts 的地址而非IP networking: podSubnet:192.168.0.0/16#<-- Match the IP range from the CNI config file # 国内源新增以下一行 imageRepository:registry.cn-hangzhou.aliyuncs.com/google_containers
初始化:
1 2 3 4 5 6 7 8
kubeadm init --config=kubeadm-config.yaml --upload-certs \ | tee kubeadm-init.out #<-- Save output for future review
wget https://github.com/dzvision/blog-issue/releases/download/v0.0.0.0.2/LFS258_V2023-09-14_SOLUTIONS.tar.xz tar -xvf LFS258_V2023-09-14_SOLUTIONS.tar.xz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
kubectl apply -f /home/student/LFS258/SOLUTIONS/s_03/cilium-cni.yaml # output serviceaccount/cilium created serviceaccount/cilium-operator created secret/cilium-ca created secret/hubble-server-certs created configmap/cilium-config created clusterrole.rbac.authorization.k8s.io/cilium created clusterrole.rbac.authorization.k8s.io/cilium-operator created clusterrolebinding.rbac.authorization.k8s.io/cilium created clusterrolebinding.rbac.authorization.k8s.io/cilium-operator created role.rbac.authorization.k8s.io/cilium-config-agent created rolebinding.rbac.authorization.k8s.io/cilium-config-agent created service/hubble-peer created daemonset.apps/cilium created deployment.apps/cilium-operator created
# Exanmple Output oot@cp:~# kubeadm init --config=kubeadm-config.yaml --upload-certs \ > | tee kubeadm-init.out [init] Using Kubernetes version: v1.27.1 [preflight] Running pre-flight checks error execution phase preflight: [preflight] Some fatal errors occurred: [ERROR Port-10259]: Port 10259 is in use [ERROR Port-10257]: Port 10257 is in use [ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists [ERROR FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml]: /etc/kubernetes/manifests/kube-controller-manager.yaml already exists [ERROR FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml]: /etc/kubernetes/manifests/kube-scheduler.yaml already exists [ERROR FileAvailable--etc-kubernetes-manifests-etcd.yaml]: /etc/kubernetes/manifests/etcd.yaml already exists [ERROR Port-10250]: Port 10250 is in use [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist [ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty # Resolution rm -f /etc/kubernetes/manifests/* rm -rf /var/lib/etcd
# Check and kill the process using port 10257 echo"Checking for port 10257" pid10257=$(sudo lsof -t -i:10257) if [ -n "$pid10257" ]; then echo"Killing process $pid10257 using port 10257" sudo kill$pid10257 else echo"No process found using port 10257" fi
# Check and kill the process using port 10259 echo"Checking for port 10259" pid10259=$(sudo lsof -t -i:10259) if [ -n "$pid10259" ]; then echo"Killing process $pid10259 using port 10259" sudo kill$pid10259 else echo"No process found using port 10259" fi
# Check and kill the process using port 10250 echo"Checking for port 10250" pid10250=$(sudo lsof -t -i:10250) if [ -n "$pid10250" ]; then echo"Killing process $pid10250 using port 10250" sudo kill$pid10250 else echo"No process found using port 10250" fi