systemctl stop firewalld
systemctl disable firewalld
sed -i ‘s/enforcing/disabled/’ /etc/selinux/config # 永久
setenforce 0 # 临时
swapoff -a
sed -ri ‘s/.swap./#&/’ /etc/fstab
hostnamectl set-hostname
cat >> /etc/hosts << EOF
192.168.178.171 k8s-master
192.168.178.172 k8s-node1
192.168.178.173 k8s-node2
EOF
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOFsysctl --system # 生效
yum install ntpdate -y
ntpdate time.windows.com
yum install -y docker
配置镜像:
vim /etc/docker/daemon.json
{
“registry-mirrors”: [“https://b9pmyelo.mirror.aliyuncs.com”],
“exec-opts”: [“native.cgroupdriver=systemd”]
}systemctl restart docker
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
dnf install -y kubernetes-kubeadm kubernetes-kubelet kubernetes-master
systemctl enable kubelet
kubeadm init
–apiserver-advertise-address=masterIp
–image-repository registry.aliyuncs.com/google_containers
–kubernetes-version v1.20.2
–service-cidr=10.96.0.0/12
–pod-network-cidr=10.244.0.0/16
- –apiserver-advertise-address 集群通告地址
- –image-repository 由于默认拉取镜像地址k8s.gcr.io国内无法访问,这里指定阿里云镜像仓库地址
- –kubernetes-version K8s版本,与上面安装的一致 kubeadm version:查看版本
- –service-cidr 集群内部虚拟网络,Pod统一访问入口
- –pod-network-cidr Pod网络,与下面部署的CNI网络组件yaml中保持一致
curl https://docs.projectcalico.org/v3.18/manifests/calico.yaml -O
启用网路组:kubectl apply -f calico.yaml
命令:kubeadm token list
结果:ff1wdt.gaop6xb7n159ob68
命令:openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed ‘s/^.* //’
结果:98448e33982b3684b0870d543eff9c9490e749588caef088f8bfe144d4f2166f
kubeadm join 主节点ip:6443 --token 上述获得的token --discovery-token-ca-cert-hash sha256:上述获得的sha256
子节点现实不是Ready稍等再次运行即可
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 3m1s v1.20.2
k8s-node1 Ready 3m14s v1.20.2
k8s-node2 Ready 3m21s v1.20.2
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
把type: ClusterIP 改为 type: NodePort
vi dash.yaml
#创建访问账号,准备一个yaml文件; vi dash.yaml apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard
应用:kubectl apply -f dash.yaml
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
kubectl get svc kubernetes-dashboard -n kubernetes-dashboard
443:30120/TCP:30120为对外访问端口
必须使用https://ip:端口访问;访问时会提示有问题链接,如果是谷歌浏览器鼠标点击该页面然后键盘输入 thisisunsafe 即可访问
每次解决问题都可以执行kubeadm reset
进行重置配置
主节点内存配置不小于4g不然会警告
一:The connection to the server localhost:8080 was refused - did you specify the right host or port?
原因:
kubernetes master没有与本机绑定集群初始化的时候没有绑定,此时设置在本机的环境变量即可解决问题。
解决:
echo “export KUBECONFIG=/etc/kubernetes/admin.conf” >> /etc/profile
source /etc/profile
二: [WARNING IsDockerSystemdCheck]: detected “cgroupfs” as the Docker cgroup driver. The recommended driver is “systemd”. Please follow the guide at https://kubernetes.io/docs/setup/cri/
cat < /etc/docker/daemon.json
{
“exec-opts”: [“native.cgroupdriver=systemd”]
}
EOFsystemctl restart docker
三:** not found path
使用yum install **
下载相对应缺失组件即可