安装kubernetes的时候,需要安装kubelet, kubeadm,kubeadm等包,但k8s官网给的yum源是packages.cloud.google.com,国内访问不了,此时我们可以使用阿里云的yum仓库镜像。
kubeadm 安装步骤
1、首先禁用防护墙
systemctl disable firewalld
systemctl stop firewalld
2、禁用SELINUX:
setenforce 0
// 查看
cat /etc/selinux/config
SELINUX=disabled
3、swapoff -a
4、创建/etc/sysctl.d/k8s.conf
文件,添加如下内容:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
5、设置k8s yum源
vi /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
6、安装kubeadm和相关工具
yum install -y docker kubelet kubeadm kubectl kubernetes-cni
7、首先执行脚本下载好所需的镜像,并修改tag
#!/bin/bash
images=(kube-proxy-amd64:v1.11.0 kube-scheduler-amd64:v1.11.0 kube-controller-manager-amd64:v1.11.0 kube-apiserver-amd64:v1.11.0
etcd-amd64:3.2.18 coredns:1.1.3 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 )
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/k8sth/$imageName k8s.gcr.io/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/k8sth/$imageName
done
images2=(k8s-dns-sidecar-amd64:1.14.9 k8s-dns-kube-dns-amd64:1.14.9
k8s-dns-dnsmasq-nanny-amd64:1.14.9 )
for imageName in ${images2[@]} ; do
docker pull registry.cn-beijing.aliyuncs.com/k8s_images/$imageName
docker tag registry.cn-beijing.aliyuncs.com/k8s_images/$imageName k8s.gcr.io/$imageName
docker rmi registry.cn-beijing.aliyuncs.com/k8s_images/$imageName
done
docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1
8、执行如下命令初始化安装
kubeadm init --kubernetes-version=1.11.0 --token-ttl 0 --pod-network-cidr=10.244.0.0/16
9、如果安装失败,重置
kukbeadm reset
10、查看相关日志
tail -n 1000 /var/log/messages
11、删除相关镜像
docker rm $(docker ps -a -q) //删除所有已经停止的容器
docker rmi --force $(docker images | grep doss-api | awk '{print $3}') //强制删除镜像名称中包含“doss-api”的镜像
docker rmi $(docker images -q)//删除所有镜像
异常总结:
1) 如果进程被占用了,2379是etcd端口,可以通过lsof -i:2379被那些端口占用,然后杀掉进程;也可以直接执行systemctl stop etcd.service
2) running with swap on is not supported. Please disable swap 不重启电脑,执行命令,立即生效swapoff -a
3) 如果出现检查异常如下,可以先执行之前安装的低版本,然后再执行上面的命令