准备工作
- 系统:CentOS 7
- CPU4核,内存4G
- 所有命令皆在root用户下运行
安装步骤
1. 关闭防火强和selinux
- 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
- 关闭selinux
setenforce 0
- 修改文件vim /etc/selinux/config
vim /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
修改前:
修改后:
2. 禁用swap
swapoff -a
3. 修改内核参数和模块
- 修改文件vim /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
- 执行命令
sysctl --system
modprobe br_netfilter
4. 安装docker
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
123456789
安装完执行下docker version,出现如下显示,说明安装完成
5. 安装kubernates组件
- 修改文件vim /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
- 执行命令
yum -y install kubelet-1.13* kubeadm-1.13* kubectl-1.13*
systemctl start kubelet
systemctl enable kubelet
此时出现错误ure could not be verified for kubernetes!
解决:repo_gpgcheck=1改为repo_gpgcheck=0!
再次执行,成功!
6. 下载kubernetes镜像
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
全部下载完成后:
7. 初始化
kubeadm init --kubernetes-version=v1.13.3 --pod-network-cidr=10.100.0.0/16
报错!
原因:我安装的docker版本太新!
解决:将docker降为19xx版本或18xx版本!
yum downgrade --setopt=obsoletes=0 -y docker-ce-19.03.13-3.el7 docker-ce-cli-19.03.13-3.el7 containerd.io*
重新执行,成功!
接下来根据提示做如下操作(ctrl c + v 即可)
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')
- 成功后执行如下命令看是否成功
kubectl get pods --all-namespaces
至此,安装成功!
- 查看节点
kubectl get nodes
附录:
参考教程
https://blog.csdn.net/weixin_43087333/article/details/119684939
安装常见问题汇总:
- https://zhuanlan.zhihu.com/p/114072542
- https://blog.csdn.net/u013355826/article/details/82790183
- https://blog.csdn.net/u013355826/article/details/82786649