P28 、基本概念——k8s的组件架构
P29 、基本概念——k8s的组件交互逻辑动画
P30、基本概念——k8s的集群安装逻辑
P31、集群搭建——服务器预选
选了青云的
P32、集群搭建——docker容器话环境安装
安装docker(3台都安装) 可以用docker info 查看镜像加速是否配置
P33、集群搭建——预备环境至此准备完成(3台都安装)
#各个机器设置自己的域名
hostnamectl set-hostname xxxx
安装k8s必须要关闭交换分区,用free -m 查看,swap要0才可以。
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
#允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
对以上的命令生效
sudo sysctl --system
P34、集群搭建——安装集群三大件(3台都安装)
安装kubelet kubeadm kubectl
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes
kubelet 现在每隔几秒就会重启,因为它陷入了一个等待 kubeadm 指令的死循环
sudo systemctl enable --now kubelet
P35、集群搭建——初始化主节点
使用kubeadm引导集群
1、下载各个机器需要的镜像
sudo tee ./images.sh <<-'EOF'
images=(
kube-apiserver:v1.20.9
kube-proxy:v1.20.9
kube-controller-manager:v1.20.9
kube-scheduler:v1.20.9
coredns:1.7.0
etcd:3.4.13-0
pause:3.2
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/$imageName
done
EOF
下载下来一个脚本然后赋予可执行权限并执行
chmod +x ./images.sh && ./images.sh
2、初始化主节点
echo "172.31.0.2 cluster-endpoint" >> /etc/hosts
在其他工作节点可以通过ping这个cluster-endpoint域名ping通。
kubeadm init \
--apiserver-advertise-address=172.31.0.2 \
--control-plane-endpoint=cluster-endpoint \
--image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \
--kubernetes-version v1.20.9 \
--service-cidr=10.96.0.0/16 \
--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/
You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:
kubeadm join cluster-endpoint:6443 --token 9y3i8m.aj2gjvdf4skl2bjd \
--discovery-token-ca-cert-hash sha256:da1e987581afa7ee22e124005877bd705182187c110894e1a45276c18b6c3052 \
--control-plane
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join cluster-endpoint:6443 --token 9y3i8m.aj2gjvdf4skl2bjd \
--discovery-token-ca-cert-hash sha256:da1e987581afa7ee22e124005877bd705182187c110894e1a45276c18b6c3052
kubectl get nodes
P36、集群搭建——Master主节点完成
1、安装网络组件 在主节点运行,把其配置文件下载来,也就是yaml文件,然后可以一键部署。 calico官网
curl https://docs.projectcalico.org/manifests/calico.yaml -O
用kubectl安装网络组件
kubectl apply -f calico.yaml
k8s命令
kubectl get nodes
kubectl apply -f xxxx.yaml
docker ps === kubectl get pods -A
kubectl get pods -A
|