k8s容器云平台,首先面临的就是安装问题,参考了官方文档也是踩了不少坑,在这里把使用kubeadm安装k8s的方法和踩的坑和大家分享一下。
一 前期准备:
我用来测试的环境是是centos7,如下
1 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
2 关闭swap内存
swapoff -a
同时修改vim /etc/fstab文件,注释掉SWAP的自动挂载
使用free -m确认swap已经关闭。
free -m
vi /etc/sysconfig/selinux
将SELINUX修改为disabled
4 调整内核参数
vim /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 修改sshd
echo "ClientAliveInterval 10" >> /etc/ssh/sshd_config
echo "TCPKeepAlive yes" >> /etc/ssh/sshd_config
systemctl restart sshd.service
二 安装
1 安装docker yum install -y docker-enginet 并重启docker服务
不同的yum源中docker的命名不尽相同 可以查看源中docker包的具体名称之后再安装
2 添加k8srepo 并安装kubeadm kubelet 和kubectl
cat /etc/yum.repos.d/kubernetes.repo
设置check=0,减少检查,使用国内阿里云镜像,否咋很难下载下来。
[kubernetes]
name=Kubernetes
baseurl=https://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
https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
然后安装
yum list installed | grep kube
yum remove kubeadm.x86_64 kubectl.x86_64 kubelet.x86_64
yum install -y kubelet-1.11.2 kubeadm-1.11.2 kubectl-1.11.2
安装制定版本
vim /var/log/messages 查看安装过程的日志
yum install -y kubelet kubeadm kubectl // 安装最新版本
sudo systemctl enable kubelet && sudo systemctl start kubelet
3 上面的1和2两步需要在所有的节点安装 针对于master节点需要进行下面操作
(1)master
kubeadm init --kubernetes-version=v1.11.2 --pod-network-cidr=10.244.0.0/16
如果失败了可以kubeadm reset 重置一下 再重新试试命令.
[init] Using Kubernetes version: v1.11.2
[init] Using Authorization modes: [Node RBAC]
[preflight] Running pre-flight checks.
[WARNING SystemVerification]: docker version is greater than the most recently validated version. Docker version: 17.12.0-ce. Max validated version: 17.03
[WARNING FileExisting-crictl]: crictl not found in system path
c Pods from directory "/etc/kubernetes/manifests".
[init] This might take a minute or longer if the control plane images have to be pulled.
........
[bootstraptoken] Using token: f184be.f642e5b3fe60b7a7
[bootstraptoken] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstraptoken] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstraptoken] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstraptoken] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: kube-dns
[addons] Applied essential addon: kube-proxy
Your Kubernetes master has initialized successfully!
You can now join any number of machines by running the following on each node
as root:
kubeadm join 172.21.0.29:6443 --token ek5wxv.70emn9h3fxmt0iag --discovery-token-ca-cert-hash sha256:17354f88ce7335f218c05eb31c6026f83f82ba37bc78dbc157fd73bd85949d10
kubeadm join 172.21.0.29:6443 --token ek5wxv.70emn9h3fxmt0iag --discovery-token-ca-cert-hash sha256:17354f88ce7335f218c05eb31c6026f83f82ba37bc78dbc157fd73bd85949d10
上面这句话记住,这样可以在其他节点上执行,来加入此集群中。
(2)master为了使得kubectl控制集群,需要做
对于非root用户
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# 对于root用户
export KUBECONFIG=/etc/kubernetes/admin.conf
# 也可以直接放到~/.bash_profile
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
(3)master安装一个network addon,执行下列命令
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
安装完之后 使用kubectl get pods –all-namespaces命令看看kube-dns是否安装成功,当kube-dns 显示running则表示成功,如下
(4)master 为了保证master的安全,master节点默认是不会被调度的。当你只有单个节点的时候,或者想使用master节点的话可以使用可以通过下面的命令取消这个限制
kubectl taint nodes --all node-role.kubernetes.io/master-
4 如果只有单个节点的话 上面的步骤已经可以搭建一个单节点的kubenetes环境,如果需要加入其他节点作为node节点进行下面的命令,将其他节点加入kubenetes集群
kubeadm join 172.21.0.29:6443 --token ek5wxv.70emn9h3fxmt0iag --discovery-token-ca-cert-hash sha256:17354f88ce7335f218c05eb31c6026f83f82ba37bc78dbc157fd73bd85949d10
https://www.cnblogs.com/liangDream/p/7358847.html