Centos7利用阿里云源安装k8s集群
2020-04-20 本文已影响0人
8a8d7f2e842b
创建主节点
#master节点:
hostnamectl set-hostname k8s-master
#修改/etc/hosts文件
cat >> /etc/hosts << EOF
192.168.92.56 k8s-master
192.168.92.57 k8s-node1
192.168.92.58 k8s-node2
EOF
#关闭防火墙和selinux
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config && setenforce 0
#关闭swap
swapoff -a
yes | cp /etc/fstab /etc/fstab_bak
cat /etc/fstab_bak |grep -v swap > /etc/fstab
安装Docker、kubeadm、kubelet、kubectl、kubernetes-cni
#配置kubernetes.repo的源,由于官方源国内无法访问,这里使用阿里云yum源
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
#在所有节点上 kubelet、kubeadm 和 kubectl、kubernetes-cni、Docker
yum install -y docker kubelet kubeadm kubectl kubernetes-cni
#启动kubelet服务
systemctl enable docker&& systemctl start docker
systemctl enable kubelet && systemctl start kubelet
打开kubectl报错error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
export KUBECONFIG=/etc/kubernetes/admin.conf
使用kubeadm 配置主节点
kubeadm init --image-repository registry.aliyuncs.com/google_containers
使用阿里云镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://apy7ox10.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
添加工作节点
#node1节点:
hostnamectl set-hostname k8s-node1
#关闭防火墙和selinux
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config && setenforce 0
kubeadm join x.x.x.x:8888 --token xx --discovery-token-ca-cert-hash xx
报错:[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables
node NotReady
KubeletNotReady runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
# 如果上面种不行就用下面命令安装
$ curl -L git.io/weave -o /usr/local/bin/weave
$ chmod a+x /usr/local/bin/weave
$ weave version