一,关闭selinux和firewalld

# setenforce 0
# systemctl stop firewalld
# sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
# systemctl disable firewalld

二,禁用swap

# swapoff -a

三,安装docker

这里可能会碰到yum源的问题,建议改成国内的源,速度比较快

# yum -y install yum-utils device-mapper-persistent-data lvm2
# yum-config-manager -y --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum -y install docker-ce-18.06.3.ce-3.el7 docker-ce-cli-18.06.3.ce-3.el7 containerd.io
# systemctl start docker
# systemctl enable docker

四:将docker镜像仓库改成国内的仓库

# mkdir /etc/docker
# cat <<EOF > /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://3laho3y3.mirror.aliyuncs.com"
  ]
}
EOF
 
# systemctl restart docker

 

五:设置阿里云yum仓库并安装kubernetes组件

# cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
# yum -y install kubelet-1.13* kubeadm-1.13* kubectl-1.13*
# systemctl start kubelet
# systemctl enable kubelet

 

六:下载k8s相关镜像并打标签

# docker pull mirrorgooglecontainers/kube-apiserver:v1.13.3
# docker pull mirrorgooglecontainers/kube-controller-manager:v1.13.3
# docker pull mirrorgooglecontainers/kube-scheduler:v1.13.3
# docker pull mirrorgooglecontainers/kube-proxy:v1.13.3
# docker pull mirrorgooglecontainers/pause:3.1
# docker pull mirrorgooglecontainers/etcd:3.2.24
# docker pull coredns/coredns:1.2.6
 
# docker tag mirrorgooglecontainers/kube-apiserver:v1.13.3 k8s.gcr.io/kube-apiserver:v1.13.3
# docker tag mirrorgooglecontainers/kube-controller-manager:v1.13.3 k8s.gcr.io/kube-controller-manager:v1.13.3
# docker tag mirrorgooglecontainers/kube-scheduler:v1.13.3 k8s.gcr.io/kube-scheduler:v1.13.3
# docker tag mirrorgooglecontainers/kube-proxy:v1.13.3 k8s.gcr.io/kube-proxy:v1.13.3
# docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
# docker tag mirrorgooglecontainers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
# docker tag coredns/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6

七:初始化k8s和网络

# kubeadm init --kubernetes-version=v1.13.3 --pod-network-cidr=10.100.0.0/16
# 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')

默认k8s的master节点是不能跑pod的业务,需要执行以下命令解除限制

# kubectl taint node kube-master node-role.kubernetes.io/master-

八: kubectl  验证是否成功即可

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐