锅炉信息网 > 锅炉知识 > 锅炉百科

K8S 集群环境搭建

发布时间:

K8S 集群环境搭建 系统配置修改替换阿里源wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7

K8S 集群环境搭建

系统配置修改

替换阿里源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo nyum makecache

关闭防火墙

systemctl stop firewalld & systemctl disable firewalld

关闭Swap

执行swapoff -a可临时关闭,但系统重启后恢复

编辑/etc/fstab,注释掉包含swap的那一行即可,重启后可永久关闭,如下所示:

/dev/mapper/centos-root / xfs defaults 0 0nUUID=20ca01ff-c5eb-47bc-99a0-6527b8cb246e /boot xfs defaults 0 0n# /dev/mapper/centos-swap swap

关闭SeLinux 执行:

setenforce 0

安装docker

yum -y install yum-utils # 添加 yum-config-manager 命令n nyum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.reponyum install docker-ce -y # 安装最新dockern n systemctl start docker n systemctl enable dockern ndocker run hello-world

修改或创建/etc/docker/daemon.json,加入下面的内容:

Copy

{n "exec-opts": ["native.cgroupdriver=systemd"]n}

卸载旧的版本包

yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64n

安装k8s

配置K8S的yum源

cat <<EOF > /etc/yum.repos.d/kubernetes.repon n[kubernetes]n nname=Kubernetesn nbaseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64n nenabled=1n ngpgcheck=0n nrepo_gpgcheck=0n ngpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpgn n http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgn nEOF

安装 K8S 组件

执行以下命令安装 kubelet、kubeadm、kubectl:

yum install -y kubelet kubeadm kubectln nsystemctl enable kubelet && systemctl start kubeletn

部署 K8S 组件

由于原镜像需要翻墙,所以从国内镜像下载Docker 镜像,然后从新改名

1)Master端:

根据所需镜像名字先拉取国内资源

docker pull mirrorgooglecontainers/kube-apiserver:v1.16.2 && docker pull mirrorgooglecontainers/kube-controller-manager:v1.16.2 && docker pull mirrorgooglecontainers/kube-scheduler:v1.16.2 && docker pull mirrorgooglecontainers/kube-proxy:v1.16.2 && docker pull mirrorgooglecontainers/pause:3.1 && docker pull mirrorgooglecontainers/etcd:3.3.10 && docker pull coredns/coredns:1.3.1

修改镜像tag

docker tag mirrorgooglecontainers/kube-apiserver:v1.16.2 k8s.gcr.io/kube-apiserver:v1.16.2 && docker tag mirrorgooglecontainers/kube-controller-manager:v1.16.2 k8s.gcr.io/kube-controller-manager:v1.16.2 && docker tag mirrorgooglecontainers/kube-scheduler:v1.16.2 k8s.gcr.io/kube-scheduler:v1.16.2 && docker tag mirrorgooglecontainers/kube-proxy:v1.16.2 k8s.gcr.io/kube-proxy:v1.16.2 && docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1 && docker tag mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10 && docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1

删除原来的镜像

docker rmi mirrorgooglecontainers/kube-apiserver:v1.16.2 && docker rmi mirrorgooglecontainers/kube-controller-manager:v1.16.2 && docker rmi mirrorgooglecontainers/kube-scheduler:v1.16.2 && docker rmi mirrorgooglecontainers/kube-proxy:v1.16.2 && docker rmi mirrorgooglecontainers/pause:3.1 && docker rmi mirrorgooglecontainers/etcd:3.3.10 && docker rmi coredns/coredns:1.3.1

2)Node端:

根据所需镜像名字先拉取国内资源

docker pull mirrorgooglecontainers/kube-proxy:v1.16.2 && docker pull mirrorgooglecontainers/pause:3.1

修改镜像tag

docker tag mirrorgooglecontainers/kube-proxy:v1.16.2 k8s.gcr.io/kube-proxy:v1.16.2 && docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1n

删除原来的镜像

docker rmi mirrorgooglecontainers/kube-proxy:v1.16.2 && docker rmi mirrorgooglecontainers/pause:3.1n

3)初始化 Master

~# kubeadm init --apiserver-advertise-address 10.9.87.0 --pod-network-cidr 10.244.0.0/16 --kubernetes-version 1.16.2

4)初始化 Node

~# kubeadm join 10.9.87.0:6443 --token a70x0p.08wolbfh169ix7du --discovery-token-ca-cert-hash sha256:e58ed8ae6bdcb65c2efa38af6f88d151d426f909d1b36e475c2eca5cbf7d3b58n

5)校验安装

~# kubectl get nodes

上一篇:k8s集群搭建

下一篇:redis sds

精选推荐

  • 711关东煮供应商
    711关东煮供应商

    今天给大家介绍三位,奶粉,全家、罗森这些便利店里关东煮的供应商。店里卖三四块钱一串的关东煮,在网上买不到,一块钱就搞定。首先关东

  • 健康日历|高压锅容易爆炸的4个原因
    健康日历|高压锅容易爆炸的4个原因

    来源:医药养生保健报设计:李雅琴医学审核:姜峰出品人:胡丽丽

  • 高炉
    高炉

    今天这活却是个白事,等到了时辰,那家人便准备火化,本来准备送普炉,我却心中一动,便对那家人说道:“这老人走也不要省,还是送高炉吧。”

  • 高压锅和电压力锅的区别,推荐几款点压力锅
    高压锅和电压力锅的区别,推荐几款点压

    记得之前有一次去朋友家玩,他正在用高压锅煮小米粥,是的,高压锅压小米粥,大概煮了半小时,高压锅突然爆炸了,现场惨不忍睹啊,幸好厨房里没

0