环境:

      centos 7.9

 

安装步骤:

一、准备:(1、SELINUX  2、swap off  3、hosts  4、sysctl配置)

setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

systemctl disable firewalld
systemctl stop firewalld
systemctl disable iptables.service
systemctl stop iptables.service

swapoff -a
sed -i '/centos-swap/d' /etc/fstab

echo '192.168.21.138 master' >> /etc/hosts

cat <<EOF > /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
modprobe br_netfilter

 

二、依赖组件安装

yum install yum-utils device-mapper-persistent-data lvm2

三、安装container

从1.24版本开始,不再依靠docker了,代替由container

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install containerd

systemctl enable containerd
systemctl restart containerd
systemctl status containerd

containerd config default > /etc/containerd/config.toml
sed -i 's#sandbox_image = "registry.k8s.io/pause:3.6"#\
sandbox_image = "registry.aliyuncs.com/google_containers/pause"#g' \
/etc/containerd/config.toml

systemctl daemon-reload
systemctl restart containerd.service

 

四、安装kubernetes(k8s)

定义阿里云镜像的repo

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

执行安装(Node结点只要let/adm即可,不需要ctl

yum install kubelet-1.26.0 kubeadm-1.26.0 kubectl-1.26.0

systemctl enable kubelet

 

五、创建k8s cluster

kubeadm init \
--apiserver-advertise-address=192.168.21.138 \     //这里IP是master的IP地址
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.26.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=192.168.0.0/16

 

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.21.138:6443 --token 8nzvev.pdlhmdg32ei6di5v \
        --discovery-token-ca-cert-hash sha256:98e42ce458a6259e4922be19e2ba73899a0b85fe89fabbe68743da8fdfc259e0r

 按照上面的提示,执行 

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

查验:kubectl get node

[root@localhost ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
master NotReady control-plane 31m v1.26.0
[root@localhost ~]#

之所以notready,需要安装calico

 

六、安装calico

根据提示的网址进入:

https://kubernetes.io/docs/concepts/cluster-administration/addons/
进入get start项,选择安装,就能看到安装步骤:

crictl config runtime-endpoint unix:///run/containerd/containerd.sock
crictl config image-endpoint unix:///run/containerd/containerd.sock


kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/custom-resources.yaml

watch kubectl get pods -n calico-system

直到全部running,要花点时间.....

 

posted on 2023-04-03 13:49  胡彼德  阅读(94)  评论(0编辑  收藏  举报