配置阿里云yum源、配置docker仓库、配置K8S的yum源
vi /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache
安装k8s的组件
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
启动kubelet并设置kubelet开机自启
systemctl enable kubelet&& systemctl start kubelet
kubeadm config images list
1、创建/etc/sysctl.d/k8s.conf文件,添加如下内容:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
执行下命令使修改生效。
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
并重启docker生效
systemctl daemon-reload
systemctl restart docker.service
k8s-docker.sh
如下
echo ""
echo "=========================================================="
echo "Pull Kubernetes v1.18.0 Images from aliyuncs.com ......"
echo "=========================================================="
echo ""
MY_REGISTRY=registry.cn-hangzhou.aliyuncs.com/openthings
# 基本组件
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.18.0
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.18.0
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.18.0
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.18.0
docker pull ${MY_REGISTRY}/k8s-gcr-io-etcd:3.4.3-0
docker pull ${MY_REGISTRY}/k8s-gcr-io-pause:3.2
docker pull ${MY_REGISTRY}/k8s-gcr-io-coredns:1.6.7
# 修改tag
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.18.0 k8s.gcr.io/kube-apiserver:v1.18.0
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.18.0 k8s.gcr.io/kube-scheduler:v1.18.0
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.18.0 k8s.gcr.io/kube-controller-manager:v1.18.0
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.18.0 k8s.gcr.io/kube-proxy:v1.18.0
docker tag ${MY_REGISTRY}/k8s-gcr-io-etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag ${MY_REGISTRY}/k8s-gcr-io-pause:3.2 k8s.gcr.io/pause:3.2
docker tag ${MY_REGISTRY}/k8s-gcr-io-coredns1.6.7 k8s.gcr.io/coredns:1.6.7
## 删除镜像
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.18.0
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.18.0
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.18.0
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.18.0
docker rmi ${MY_REGISTRY}/k8s-gcr-io-etcd:3.4.3-0
docker rmi ${MY_REGISTRY}/k8s-gcr-io-pause:3.2
docker rmi ${MY_REGISTRY}/k8s-gcr-io-coredns:1.6.7
echo ""
echo "=========================================================="
echo "Pull Kubernetes v1.18.0 Images FINISHED."
echo " by https://blog.csdn.net/yulong_1988"
echo "=========================================================="
echo ""
初始化呢
kubeadm init --kubernetes-version=1.18.0 --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=192.168.0.7
出错了
vim /etc/docker/daemon.json
{
“exec-opts”: [“native.cgroupdriver=systemd”],
“registry-mirrors”: [“https://xxxxx.mirror.aliyuncs.com”]
并重启docker生效
systemctl daemon-reload
systemctl restart docker.service
swapoff -a #临时关闭
vim /etc/fstab #注释掉swap即可永久关闭
成功