安装docker
依赖包
yum -y install yum-utils
配置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装管理容器从创建到终止整个生命周期的核心软件组件
yum -y install containerd.io
设置开机自启
systemctl enable containerd.service --now
安装k8s的kubeadm,kubelet,kubectl
配置yum源
[kubernetes]<br>name=Kubernetes<br>baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch<br>enabled=1<br>gpgcheck=1<br>repo_gpgcheck=1<br>gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg<br>
安装软件
主节点:yum -y install kubelet kubeadm kubectl --disableexcludes=kubernetes
副节点:yum -y install kubelet kubeadm --disableexcludes=kubernetes
启动kubectl
systemctl enable --now kubelet
初始化master节点
<font color="#ed2513">1.启动bridge</font>
modprobe br_netfilter
<font color="#ed2513">2.打开网桥功能</font>
sysctl -w net.bridge.bridge-nf-call-iptables=1
<font color="#ed2513">3.打开路由功能</font>
sysctl -w net.ipv4.ip_forward=1
<font color="#ed2513">4.配置套接字</font>
crictl config image-endpoint unix:///run/containerd/containerd.sock
crictl config runtime-endpoint unix:///run/containerd/containerd.sock
<font color="#ed2513">5.把配置文件写到配置目录</font>
containerd config default > /etc/containerd/config.toml
<font color="#ed2513">6.把补全命令写到环境变量里</font>
crictl completion >> /root/.bash_profile
systemctl restart containerd.service
source /root/.bash_profile
yum -y install bash-completion
子主题
kubeadm init --apiserver-advertise-address 172.17.0.70(本机IP地址) --pod-network-cidr=10.244.0.0/16(容器网络)
若想将容器网络修改网段的话修改finally配置文件
kube-finnel.yml
<font color="#5b79e8">安装finally</font>
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
<font color="#5b79e8">家目录配置密钥</font>
mkdir .kube
cp /etc/kubernetes/admin.conf .kube/config
即可运行:kubectl get node
<font color="#ed77b6">加入计算节点(计算节点运行)</font>
kubeadm join 172.17.0.70:6443 --token fpmtfd.xufy6cg02y6goj1 --discovery-token-ca-cert-hash sha256:xxxxxxxxxxx(密钥)
刷新密钥
kubeadm token create --print-join-command
K8s自带pod的作用
Controller Manager
作用:保障容器的数量是客户所需求
apiserver
作用:下发命令,查询,创建,删除等
查看api版本命令:kubectl get apiservices.apiregistration.k8s.io
kube-proxy
作用:代替原来的docker-proxy