kubeadmin安装最新版本的kubenets

系统设置

CentOS Linux release 7.6.1810 (Core)

设置本地解析

vim /etc/hosts 172.16.227.40 k8s-master

关闭及禁用防火墙

systemctl disable firewalld

systemctl stop firewalld

关闭selinux

sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config

设置启动参数

cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system

 

安装docker,kubeadm, kubelet and kubectl

安装docker

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum list docker-ce --showduplicates | sort -r

yum install docker-ce-18.06.3.ce-3.el7(不能安装默认版本1.13.1,默认版本在容器中无法执行docker命令)

报错原因查看:https://blog.csdn.net/Roger0622/article/details/108719751

systemctl start docker systemctl enable docker

kubeadm, kubelet and kubectl

cat <<EOF > /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
EOF

 

yum install -y kubelet kubeadm kubectl

systemctl enable kubelet && systemctl start kubelet

# 添加--image-repository参数,默认镜像下载会失败,

kubernetes-version与上面安装的kubelet版本对应一样

只有master节点需要执行,node节点只要安装docker与kubelet,kubeadm,kubelet就可以

kubeadm init --kubernetes-version=???. --pod-network-cidr=10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers

设置kubectl命令

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

安装pod network

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

kubectl apply -f  kube-flannel.yml

执行上面命令出错时提示如下:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

解决办法:

配置kubenetes的flannel网络的时候,出现以下报错

The connection to the server localhost:8080 was refused - did you specify the right host or port?

 

 

原因:kubenetes master没有与本机绑定,集群初始化的时候没有设置

解决办法:执行以下命令   export KUBECONFIG=/etc/kubernetes/admin.conf

/etc/kubernetes/admin.conf这个文件主要是集群初始化的时候用来传递参数的


这样默认安装好只有一个master节点
要想在主节点运行pods,还需要
 
5.0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.

解决方法是安装flannel

有时候一个pod创建之后一直是pending,没有日志,也没有pull镜像,describe的时候发现里面有一句话: 1 node(s) had taints that the pod didn't tolerate.

直译意思是节点有了污点无法容忍,执行 kubectl get no -o yaml | grep taint -A 5 之后发现该节点是不可调度的。这是因为kubernetes出于安全考虑默认情况下无法在master节点上部署pod,于是用下面方法解决:

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


新节点加入k8s集群
重复以上步骤,安装docker kubelet kubeadm kubectl
注意,node节点的kubelet这些版本要与master节点的版本相同
注意:node节点加入时要确保kubelet的cgroups与docker的cgroups一样,当执行kubeadm join提示warning时,

[WARNING IsDockerSystemdCheck]: detected “cgroupfs“ as the Docker cgroup driver. Th

加入不了节点,会一直提示kubelet不健康,解决办法如下:

https://blog.csdn.net/zhangbaoxiang/article/details/107422299


不用安装kube-flannel.yml,因为node节点加入集群后,会自动拉镜像安装
注意,k8s的master通过init初始化后,生成的token会24小时后失效,要重新生成
https://blog.csdn.net/wo18237095579/article/details/89884369
https://www.cnblogs.com/histyle/p/10897163.html
 

posted on 2020-03-23 20:27  一直用这名字  阅读(1378)  评论(0编辑  收藏  举报

导航