美文网首页
【1】Kubernetes集群搭建

【1】Kubernetes集群搭建

作者: 小毛1221 | 来源:发表于2019-10-10 23:16 被阅读0次

参考:http://docs.kubernetes.org.cn/459.htmlhttps://www.jianshu.com/p/e43f5e848da1

# 换源
cd /etc/yum.repos.d/
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
 
# 安装docker
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache
sudo yum install docker-ce -y
 
# 启动docker
sudo systemctl start docker
sudo systemctl enable docker
 
# 关闭防火墙
sudo systemctl stop firewalld
sudo systemctl disable firewalld
 
 
#关闭swap
swapoff -a
 
# 关闭SeLinux
setenforce 0
 
# 安装kubelet kubeadm kubectl
yum install -y kubelet kubeadm kubectl
 
 
# 启动kubelet
sudo systemctl enable kubelet
sudo systemctl start kubelet
 
# 初始化,使用flannel作为网络插件、使用阿里云的镜像仓库
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers
 
# 创建.kube/config
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
 
# 安装flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
 
# 可以在主节点上分配pod(可选)
kubectl taint nodes --all node-role.kubernetes.io/master-
 
# 在从节点上执行,在主节点执行kubeadm init后会显示相应token
sudo kubeadm join 172.16.32.33:6443 --token qol2os.g709t4ia2qfpt14z \
    --discovery-token-ca-cert-hash sha256:fffbc158e6f1d55d3dfff2ee3273eec777db2e2d6d5fefaa6e2b13ca8090f8c8
 
 
# 将主节点的配置信息拷贝到从节点,可以在从节点上使用kubectl
scp root@<master ip>:/etc/kubernetes/admin.conf ./kube/config
# 如果报错
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR DirAvailable--etc-kubernetes-manifests]: /etc/kubernetes/manifests is not empty
    [ERROR FileAvailable--etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
    [ERROR Port-10250]: Port 10250 is in use
    [ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
 
# 使用重置
sudo kubeadm reset

相关文章

网友评论

      本文标题:【1】Kubernetes集群搭建

      本文链接:https://www.haomeiwen.com/subject/gbkmyctx.html