赞
踩
服务器 | 功能 | ip | 备注 |
A | 管理节点、工作节点 | 10.10.xx.13x | |
B | 工作节点 | 10.10.xx.23x | |
C | 工作节点 | 10.10.xx.xx |
master
node
总结一下:Pod被ReplicaSet管理,ReplicaSet控制pod的数量;ReplicaSet被Deployment管理,Deployment控制pod应用的升级、回滚,当然也能控制pod的数量。Service提供一个统一固定入口,负责将前端请求转发给Pod。
借助ntp服务设置各节点的时间同步
- yum -y install chrony
- systemctl start chronyd && systemctl enable chronyd
- chronyc sources
通过DNS完成各节点名称解析,测试环境主机,测试用hosts文件代替(各个节点同步设置)
- 10.10.10.137 k8s-master01
- 10.10.10.236 k8s-node01
- 10.10.10.52 k8s-node02
-
- hostnamectl set-hostname k8s-master01
- hostnamectl set-hostname k8s-node01
- bash
配置ssh免密登入
- ssh-keygen -t rsa
- ssh-copy-id k8s-node01
- ssh-copy-id k8s-node02
禁用SELinux&禁用Swap设备
- swapoff -a && sed -i '/ swap / s/^\\(.*\\)$/#\\1/g' /etc/fstab
- setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
- free -m
关闭各节点iptables和firewalld服务(可选择打开端口)
- firewall-cmd --permanent --add-port=6443/tcp
- firewall-cmd --permanent --add-port=2379-2380/tcp
- firewall-cmd --permanent --add-port=10248/tcp
- firewall-cmd --permanent --add-port=10249/tcp
- firewall-cmd --permanent --add-port=10250/tcp
- firewall-cmd --permanent --add-port=10251/tcp
- firewall-cmd --permanent --add-port=10252/tcp
- firewall-cmd --permanent --add-port=10255/tcp
- firewall-cmd --permanent --add-port=8472/udp
- firewall-cmd --permanent --add-port=443/udp
- firewall-cmd --permanent --add-port=53/udp
- firewall-cmd --permanent --add-port=53/tcp
- firewall-cmd --permanent --add-port=9153/tcp
- # only if you want NodePorts exposed on control plane IP as well
- firewall-cmd --permanent --add-port=30000-32767/tcp
- firewall-cmd --add-masquerade --permanent
- firewall-cmd --reload
- systemctl restart firewalld
- firewall-cmd --permanent --add-port=10250/tcp
- firewall-cmd --permanent --add-port=10255/tcp
- firewall-cmd --permanent --add-port=8472/udp
- firewall-cmd --permanent --add-port=443/udp
- firewall-cmd --permanent --add-port=30000-32767/tcp
- firewall-cmd --permanent --add-port=53/udp
- firewall-cmd --permanent --add-port=53/tcp
- firewall-cmd --permanent --add-port=9153/tcp
- firewall-cmd --add-masquerade --permanent
- systemctl restart firewalld
8472/udp为flannel的通信端口
443/tcp 为Kubernetes server端口
注意一点:一定要执行以下命令打开NAT,默认是关闭状态,这里踩过坑!!
1 2 3 4 5 |
|
如果你使用了istio还有把istio-pilot的端口加到防火墙里:
1 |
|
参考docker官网
1、更新yum源(各节点)
- 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=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
2、安装、开机自启kubelet(各节点)
- yum -y install kubelet kubectl kubeadm
- systemctl enable kubelet
3、配置Master节点初始化
kubeadm version #查看安装的版本 kubeadm init --kubernetes-version="v1.23.1" --pod-network-cidr=10.80.0.0/16 --image-repository registry.aliyuncs.com/google_containers #初始化 mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config export KUBECONFIG=/etc/kubernetes/admin.conf
4、在master中安装flannel插入
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml如果wget下载有问题就用其他方法把yml文件下载下来 kubectl apply -f kube-flannel.yml
用kubectl查看状态是否变化为Ready。
kubectl get nodes
5、生成token
- #如果过期可先执行此命令
- kubeadm token create #重新生成token
- #列出token
- kubeadm token list | awk -F" " '{print $1}' |tail -n 1
6、获取CA公钥的哈希值
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^ .* //'
7、加入node
kubeadm join k8s-master01:6443 --token qzj6hk.dolv4zlcscqkoc5e --discovery-token-ca-cert-hash sha256:fe8b1ce25d0e121bf874ebfb7353eb5fa8a5531d7aed7aa22b41ef9f5e051ca8
8、查看节点是否加入
kubectl get nodes
9、安装dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
kubectl proxy --address=192.168.112.38 --disable-filter=true &
10、安装dashboard
wget https://kuboard.cn/install-script/kuboard.yaml
kubectl apply -f kuboard.yaml
kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep kuboard-user | awk '{print $1}') -o go-template='{{.data.token}}' | base64 -d
http://ip:32567/dashboard
1、kubelet服务启动失败
注意kubelet的cgroup和docker都设置为systemd
journalctl -f -u kubelet 查看日志发现,报错如下:
kubelet cgroup driver: “cgroupfs” is different from docker cgroup driver: “systemd”
这个里要修改3个配置文件为systemd
1.vim /etc/docker/daemon.json
"exec-opts": ["native.cgroupdriver=systemd"]2.vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
在KUBELET_KUBECONFIG_ARGS 后面追加 --cgroup-driver=systemdEnvironment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --cgroup-driver=systemd"
3.vim /var/lib/kubelet/kubeadm-flags.env
KUBELET_KUBEADM_ARGS="--cgroup-driver=systemd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.2"
systemctl daemon-reload
systemctl restart kubelet
2、master节点可以当node使用
kubectl taint nodes --all node-role.kubernetes.io/master
3、 外部访问dashboard
首先在跳板机上启动 kube-proxy (假设跳板机的 hostname 是
ttg11
):kubectl proxy --address='0.0.0.0' --accept-hosts='^\*$' &
然后本地 ssh 端口转发到跳板机:
ssh -L localhost:8001:localhost:8001 -NT weiping@ttg11然后通过如下本地地址访问:
4、pod在node上创建一直creating
network: failed to set bridge addr: "cni0" already has an IP address
rm -rf /var/lib/cni/ rm -rf /etc/cni/ ifconfig cni0 down ip link delete cni0
5、 pod删除不掉
强制删除
kubectl delete pod -n go-test --force gotest-backend-deployment-6796ccf98c-f65bv
6、Kubernetes对Pod调度指定Node以及Node的Taint 和 Toleration
7、k8s集群中node部署下载镜像失败
cp ~/.docker/config.json /var/lib/kubelet/config.json
8、node打标签做亲和性调度
kubectl label nodes <node-name> <label-key>=<label-value>
9、namespace删不掉
通过命令查看
kubectl edit namespace cert-manager
10、CRD启动失败,调用异常
E0323 07:50:56.028622 1 wrap.go:39] apiserver panic'd on GET /apis/apps.iluvatar.ai/v1/workflows?limit=500&resourceVersion=0
I0323 07:50:56.028691 1 log.go:172] http2: panic serving 10.10.10.137:44722: runtime error: invalid memory address or nil pointer dereference
kubernets版本16.0有问题,16.2+和15.5+修复,或删除[x-kubernetes-int-or-string]
11、dns不通出现pod解析域名错误
dns.resolver.NoNameservers: All nameservers failed to answer the query service-registry.skydiscovery-system. IN A: Server 10.96.0.10 UDP port 53 answered SERVFAIL
flannel模块网络配置问题
kubeadm init --kubernetes-version="v1.15.5" --pod-network-cidr=192.168.0.0/16 --service-cidr=10.96.0.0/12 --image-repository registry.aliyuncs.com/google_containers
kube-flannel.yml
net-conf.json: |
{
"Network": "192.168.0.0/16",
"Backend": {
"Type": "vxlan"
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。