微服务(二)| k8s安装
安装Kubeadm
cat <<EOF | tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 #repo_gpgcheck=1 gpgkey=https://mirrors. aliyun.com/kubernetes/yum/doc/yum-key.gpg EOF
yum install -y kubelet-1.28.0 kubeadm-1.28.0 kubectl-1.28.0 --disableexcludes=kubernetes
systemctl enable --now containerd systemctl enable --now kubelet
初始化master
生成token
kubeadm token generate
使用配置文件
kubeadm config print init-defaults --component-configs KubeletConfiguration,KubeProxyConfiguration > kubeadm.yaml
修改kubeadm.yaml
token: 上面生成的token
localAPIEndpoint:
advertiseAddress: 192.168.0.15
nodeRegistration:
name: k8s-master1
imageRepository: registry.aliyuncs.com/google_containers
kubernetesVersion: 1.28.0
ipvs:
strictARP: true
mode: "ipvs"
然后安装
kubeadm init --config kubeadm.yaml --v 6
看到下面的内容表示安装成功了
.....
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.0.11:6443 --token vpbpo2.a73mc0asxjy7b5xe \
--discovery-token-ca-cert-hash sha256:70ba6173c9e2ce7b285342afb456e566f03fd8eb99edc7609edd86ae1e82c335
记住上面的kubeadm join的命令,其它服务器可以通过这个命令加入到集群中
安装命令
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
安装网络插件calico
wget https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml
修改为kubeadm.yaml中的podSubnet:
- name: CALICO_IPV4POOL_CIDR
value: "10.96.0.0/12"
在master主机上安装即可
kubectl apply -f calico.yaml
等待所有节点status变成Ready
watch kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-7ddc4f45bc-lcbx6 1/1 Running 0 65s
calico-node-pvpbx 1/1 Running 0 65s
coredns-66f779496c-8xplr 1/1 Running 0 2m9s
coredns-66f779496c-gnq7l 1/1 Running 0 2m9s
etcd-k8s-master 1/1 Running 0 2m15s
kube-apiserver-k8s-master 1/1 Running 0 2m15s
kube-controller-manager-k8s-master 1/1 Running 0 2m15s
kube-proxy-98kx5 1/1 Running 0 2m10s
kube-scheduler-k8s-master 1/1 Running 0 2m15s
初始化node
kubeadm join 192.168.0.11:6443 --token vpbpo2.a73mc0asxjy7b5xe --discovery-token-ca-cert-hash sha256:70ba6173c9e2ce7b285342afb456e566f03fd8eb99edc7609edd86ae1e82c335
0