K8S集群搭建案例
参考文档:
https://yq.aliyun.com/articles/419570?spm=5176.10695662.1996646101.searchclickresult.547174c9nMJ4R6
编辑 hosts文件(主节点):
echo "`ifconfig | grep broadcast | awk -F'netmask' '{print $1}' | awk -F' ' '{print $2}'` k8s-master " >> /etc/hosts echo "`ifconfig | grep broadcast | awk -F'netmask' '{print $1}' | awk -F' ' '{print $2}'` etcd" >> /etc/hosts echo "`ifconfig | grep broadcast | awk -F'netmask' '{print $1}' | awk -F' ' '{print $2}'` registry" >> /etc/hosts
echo "nodeip k8s-node-1" >> /etc/hosts #nodeip 替换为node节点的ip地址
将配置好的hosts文件拷贝到Node节点:
scp /etc/hosts root@k8s-node-1:/etc/hosts
环境准备(Master节点):
hostnamectl --static set-hostname k8s-master
环境准备(Slave节点):
hostnamectl --static set-hostname k8s-node-1
关闭防火墙(主、备节点上都执行):
systemctl disable firewalld.service systemctl stop firewalld.service
关闭SELinux:
setenforce 0 sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
在Master节点上需要安装的服务(点击相应的服务会打开对应的服务的安装配置方法):
[ docker | etcd | flannel | kube-apiserver、kube-scheduler、kube-controller-manager (yum -y install kubernetes 后启动这三个服务) ] <验证集群状态:>
在Slave(Node)节点上需要安装的服务:
[ docker | flannel | kubelet、kube-proxy (yum -y install kubernetes 后启动这两个个服务) ]
1.解决kubectl get pods时 No resources found的问题: [如果K8S部署是按照上文来的,不会发生此问题]
1、vi /etc/kubernetes/apiserver 2、找到 "KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota",去掉ServiceAccount,保存退出。 3、systemctl restart kube-apiserver
2.解决在pul镜像image的时候没有凭据,没有redhat-ca.crt文件的问题: [如果K8S部署是按照上文来的,不会发生此问题]
[具体报错:Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ... open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory]
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem //前两个命令会生成/etc/rhsm/ca/redhat-uep.pem文件. docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest