集群搭建方法 1.minikuber 2.kubeadm 3.二进制 4.命令行
K8S组件 控制面板Master
kube-apiserver
kube-controller-manager
cloud-controller-manager
kube-scheduler
etcd
节点组件
kubelet
kube-proxy
container tuntime
附件组件
kube-dns,域名服务
ingress Conttroller,外部网络
Headpster,prometheus,资源监控
Dashboard,控制台界面
Federation,夸可用区
Fluentd-elasticsearch,日志收集
分层架构
ecosystem,最顶层-生态系统,
interfaceLayer,接口层
管理层
应用层
核心层
专业术语
无状态应用:不会对本地环境产生依赖,例如不会存储数据的到本地磁盘,例如nginx
有状态应用:会对本地环境产生依赖,例如需要存储数据到本地磁盘,例如mysql好数据持久化的redis
资源和对象-元数据级别
HPA 自动扩容缩容
podTemplate,用于pod 自动伸缩扩容使用
LimitRange,限定资源使用限制
资源和对象-集群
namespace
node
clusterRole
clusetrRoleBinding
资源和对象-命名空间
视频安装的版本:
K8S=1.23.6
docker=20+
1.24 之后不支持 docker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 # 关闭防火墙 systemctl stop firewalld systemctl disable firewalld # 关闭selinux sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久 setenforce 0 # 临时 # 关闭swap swapoff -a # 临时 sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久 # 关闭完swap后,一定要重启一下虚拟机!!! # 根据规划设置主机名 hostnamectl set-hostname <hostname> # 在master添加hosts cat >> /etc/hosts << EOF 172.19.0.3 k8s-master 172.19.0.12 k8s-node1 172.19.0.11 k8s-node2 EOF # 将桥接的IPv4流量传递到iptables的链 cat > /etc/sysctl.d/k8s.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system # 生效 # 时间同步 yum install ntpdate -y ntpdate time.windows.com
cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6
yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6
systemctl enable kubelet
# 配置关闭 Docker 的 cgroups,修改 /etc/docker/daemon.json,加入以下内容 “exec-opts”: [“native.cgroupdriver=systemd”]
# 重启 docker systemctl daemon-reload systemctl restart docker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 # 在 Master 节点下执行 kubeadm init \ --apiserver-advertise-address=172.19.0.3 \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version v1.23.6 \ --service-cidr=10.96.0.0/12 \ --pod-network-cidr=10.244.0.0/16 # 安装成功后,复制如下配置并执行 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 nodes ----------- [addons] Applied essential addon: kube-proxy 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 172.19.0.3:6443 --token gkd23q.4wn0brlj6j1swkji \ --discovery-token-ca-cert-hash sha256:690c3205c33fea3196aa5db5229d1501a4cff48ae03bcb3a17deda2d77d27081
查看历史token
kubeadm token list
Aug 19 20:27:19 k8s-node1 kubelet[13150]: E0819 20:27:19.600257 13150 server.go:205] “Failed to load kubelet config file” err=”failed to load Kubelet config file /var/lib/kubelet/config.yaml, error failed to read kubelet config file "/var/lib/kubelet/config.yaml", error: open /var/lib/kubelet/config.yaml: no such file or directory” path=”/v