centos安装docker+K8s(通过kubeadm)

一. 安装docker

1.添加yum国内依赖

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2.安装docker

yum -y install docker-ce docker-ce-cli containerd.io

3.启动docker

systemctl start docker

4.添加开机自启

systemctl enable docker

二.安装k8s

1.配置k8s 国内yum源

## 新建k8s.repo文件
vim /etc/yum.repo.d/k8s.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

2.安装kubeadm,kubelet, kubectl

yum install -y kubelet kubernetes-cni kubeadm
# 设置开机自启并立即启动
systemctl enable kubelet
systemctl start kubelet

3.配置kubeadm.yml并下载所需镜像

vim kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: "v1.18.2”
imageRepository: "registry.aliyuncs.com/google_containers"
networking:
  podSubnet: "10.244.0.0/16"

拉取镜像(可能需要先修改主机名:hostnamectl set-hostname young)

kubeadm --config kubeadm.yaml config images pull

4.修改镜像tag(注意版本,按照你的版本修改)

docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.18.2 k8s.gcr.io/kube-proxy:v1.18.2
docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.18.2 k8s.gcr.io/kube-scheduler:v1.18.2
docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.18.2 k8s.gcr.io/kube-apiserver:v1.18.2
docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.18.2 k8s.gcr.io/kube-controller-manager:v1.18.2
docker tag registry.aliyuncs.com/google_containers/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag registry.aliyuncs.com/google_containers/coredns:1.6.7 k8s.gcr.io/coredns:1.6.7
docker tag registry.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2

5.初始化k8s集群(注意版本)

kubeadm init --kubernetes-version=1.18.2 --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=NumCPU

centos安装docker+K8s(通过kubeadm)_第1张图片

6.配置环境变量

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

7.安装配置网络

kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml

8.配置master节点可调度(默认master节点不可调度,即不可运行pod)

kubectl taint nodes --all node-role.kubernetes.io/master-

在这里插入图片描述

你可能感兴趣的:(云计算)