本地搭建3节点kubernetes
2021-04-17 20:26
标签:top k RKE hash tar systemctl 安装docker port 问题 列表 master内存至少4GiB sysctl --system 参见网络其他文章 安装master,法一: return a token To start using your cluster, you need to run the following as a regular user: 系统设置 配置k8s,docker yum源 下载docker kubelet kubeadm 通过tocken加入集群。 注意tocken的有效期为24小时 yaml文件 修改nodePort kubectl patch svc -n kube-system kubernetes-dashboard -p ‘{"spec":{"type":"NodePort"}}‘ kubectl create serviceaccount dashboard-admin -n kube-system kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin kubectl describe secret -n kube-system dashboard-admin 查看安装 本地搭建3节点kubernetes 标签:top k RKE hash tar systemctl 安装docker port 问题 列表 原文地址:https://www.cnblogs.com/showmycode/p/12290035.htmlkubernetes本地搭建版本选择
CentOS 环境准备
3台机器环境检查
sudo swapoff -a
sudo vi /etc/fstab
把/dev/mapper/centos-swap swap这行注释掉
cat > /etc/sysctl.d/k8s.conf
hostnamectl set-hostname xx
cat >> /etc/hosts
yum源及安装
# k8s yum源
cat > /etc/yum.repos.d/kubernetes.repo >
cd /etc/yum.repos.d
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all
yum repolist
yum install -y docker-ce kubeadm kubelet kubectl
systemctl enable --now docker && systemctl enable --now kubelet
systemctl status kubelet
journalctl -xeu kubelet
kubernetes环境搭建
安装k8s master
查询列表kubeadm config images list
kubeadm config print init-defaults > kubeadm.yaml
cat kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
nodeRegistration: # 去掉master污点
taints:
- effect: PreferNoSchedule
key: node-role.kubernetes.io/master
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
imageRepository: registry.aliyuncs.com/google_containers # images地址
kubernetesVersion: v1.17.0 # version
EOF
kubeadm init --config kubeadm.yaml | tee kubeadmin.log
token expiredkubeadm token create --print-join-command
kubeadm join 172.17.55.202:6443 --token 4xv6eq.5kygve4g6uy1smat \ --discovery-token-ca-cert-hash sha256:3ab287132d40f511925d0e416a6a0bd1fba47697c447b6c05f421b12029b8766
kubeadm reset
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
rm -rf $HOME/.kube/config
systemctl stop docker
systemctl stop kubelet
yum remove kubelet
iptables -tnat --flush # iptables 一定要刷新
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
初始化网络插件
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d ‘\n‘)"启动worker节点
补充其他插件
添加dashboard
https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/#deploying-the-dashboard-ui
添加存储
kubectl get pods -n rook-ceph-system
kubectl get pods -n rook-ceph
搭建过程中问题
# coredns readiness 一直unhealthy
coredns dial tcp 10.96.0.1:443: connect: no route to host
# 问题
iptables混乱导致
# 解决办法
systemctl stop kubelet
systemctl stop docker
iptables --flush
iptables -tnat --flush
systemctl start kubelet
systemctl start docker
kubectl delete pod weave -n kube-system