鍚桄明月 發表於 2020-2-24 17:58:00

centos 7 安装 kubernetes

<p>1、参考文章</p>
<p>https://blog.51cto.com/3241766/2405624</p>
<p>(这个文章写的条理挺好的,但是其中有好几个地方会存在一些问题,在此文章最后面已经写明,可以参考一下)</p>
<p>https://www.cnblogs.com/Erik_Xu/p/8783789.html</p>
<p>&nbsp;</p>
<p>2、软件版本相关概览</p>
<p><img src="https://img2018.cnblogs.com/i-beta/974873/202002/974873-20200224161003317-126853916.png" alt="" width="1080" height="116"></p>
<p>&nbsp;Centos 7.6安装参考:</p>
<p>https://www.cnblogs.com/zhuzi91/p/12356856.html&nbsp;</p>
<p>&nbsp;</p>
<p>安装步骤包含如下部分</p>
<p>1、docker&nbsp;安装(两个节点都要执行)</p>
<p>2、k8s&nbsp;安装准备工作(两个节点都要执行)</p>
<p>3、Master&nbsp;节点安装</p>
<p>4、Node&nbsp;节点安装</p>
<p>5、DashBoard&nbsp;安装(这个部分浏览器访问的时候一直不出来,暂时还不知道是什么原因)</p>
<p>6、集群测试</p>
<p>&nbsp;</p>
<h2>1、Docker&nbsp;安装(两个节点都要执行)</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 128, 1)">1</span>&gt;<span style="color: rgba(0, 0, 0, 1)">、docker 安装
    </span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">)、移除旧版本的 docker
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> remove docker docker-common docker-selinux docker-<span style="color: rgba(0, 0, 0, 1)">engine
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> remove docker-<span style="color: rgba(0, 0, 0, 1)">ce
    </span><span style="color: rgba(0, 0, 255, 1)">rm</span> -rf /var/lib/<span style="color: rgba(0, 0, 0, 1)">docker

    </span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">)、查看有没有安装
    rpm </span>-qa|<span style="color: rgba(0, 0, 255, 1)">grep</span> device-mapper-persistent-<span style="color: rgba(0, 0, 0, 1)">data
    rpm </span>-qa|<span style="color: rgba(0, 0, 255, 1)">grep</span><span style="color: rgba(0, 0, 0, 1)"> lvm2

    </span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">)、安装
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> <span style="color: rgba(0, 0, 255, 1)">install</span> -y <span style="color: rgba(0, 0, 255, 1)">yum</span>-utils device-mapper-persistent-<span style="color: rgba(0, 0, 0, 1)">data lvm2

    </span><span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">)、配置镜像地址
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span>-config-manager --add-repohttps:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">download.docker.com/linux/centos/docker-ce.repo</span>

    <span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(0, 0, 0, 1)">)、然后修改镜像地址,更改为国内的,这样可以下载快一点
    vim </span>/etc/<span style="color: rgba(0, 0, 255, 1)">yum</span>.repos.d/docker-<span style="color: rgba(0, 0, 0, 1)">ce.repo
    修改地址为清华的
    </span>%s@https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">download.docker.com@</span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">https://mirrors.tuna.tsinghua.edu.cn/docker-ce</span>

    <span style="color: rgba(128, 0, 128, 1)">6</span><span style="color: rgba(0, 0, 0, 1)">)、更新缓存
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span><span style="color: rgba(0, 0, 0, 1)"> makecache fast


</span><span style="color: rgba(128, 0, 128, 1)">2</span>&gt;<span style="color: rgba(0, 0, 0, 1)">、docker ce安装
    </span><span style="color: rgba(128, 0, 128, 1)">1</span>)、安装最新版的 docker-<span style="color: rgba(0, 0, 0, 1)">ce
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> <span style="color: rgba(0, 0, 255, 1)">install</span> -y docker-ce docker-ce-<span style="color: rgba(0, 0, 0, 1)">cli containerd.io
    ##安装指定版本docer</span>-<span style="color: rgba(0, 0, 0, 1)">ce 可使用以下命令查看
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> list docker-ce.x86_64 --showduplicates |<span style="color: rgba(0, 0, 255, 1)">sort</span> -<span style="color: rgba(0, 0, 0, 1)">r

    ##安装完成之后可以使用命令查看
    docker version

</span><span style="color: rgba(128, 0, 128, 1)">3</span>&gt;<span style="color: rgba(0, 0, 0, 1)">、配置 docker 镜像加速
    vim </span>/etc/docker/<span style="color: rgba(0, 0, 0, 1)">daemon.json
    {
      </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">registry-mirrors</span><span style="color: rgba(128, 0, 0, 1)">"</span> : [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">https://v16stybc.mirror.aliyuncs.com</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
    }

    ##通知 systemd 重载此配置文件
    systemctl daemon</span>-<span style="color: rgba(0, 0, 0, 1)">reload

    ##设置开机启动
    systemctl enable docker

    ##启动 docker
    systemctl start docker</span></pre>
</div>
<h2>2、k8s&nbsp;准备工作相关(两个节点都要执行)</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">k8s 相关配置
</span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">)、设置系统主机名以及 Host 文件的相互解析
    hostnamectlset</span>-<span style="color: rgba(0, 0, 255, 1)">hostname</span>k8s-<span style="color: rgba(0, 0, 0, 1)">master01

</span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">)、修改 hosts 文件
    vim </span>/etc/<span style="color: rgba(0, 0, 0, 1)">hosts
    </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">56.2</span> k8s-<span style="color: rgba(0, 0, 0, 1)">master01
    </span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">56.3</span><span style="color: rgba(0, 0, 0, 1)"> node01

</span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">)、验证 uuid 和 mac 地址(enp0s3 根据自己的进入相应的目录,ip addr 看一下网卡的名字即可)
</span><span style="color: rgba(0, 0, 255, 1)">cat</span> /sys/class/net/enp0s3/<span style="color: rgba(0, 0, 0, 1)">address
</span><span style="color: rgba(0, 0, 255, 1)">cat</span> /sys/class/dmi/<span style="color: rgba(0, 0, 255, 1)">id</span>/<span style="color: rgba(0, 0, 0, 1)">product_uuid

</span><span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">)、安装依赖包
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> <span style="color: rgba(0, 0, 255, 1)">install</span> -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wgetvimnet-<span style="color: rgba(0, 0, 0, 1)">tools git

</span><span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(0, 0, 0, 1)">)、设置防火墙为 Iptables 并设置空规则
    systemctlstop firewalld</span>&amp;&amp;<span style="color: rgba(0, 0, 0, 1)">systemctldisable firewalld

    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> -y <span style="color: rgba(0, 0, 255, 1)">install</span> iptables-services&amp;&amp;systemctlstart iptables&amp;&amp;systemctlenable iptables&amp;&amp;iptables -F&amp;&amp;<span style="color: rgba(0, 0, 0, 1)">service iptables save

</span><span style="color: rgba(128, 0, 128, 1)">6</span>)、关闭 SELINUX(临时禁用&amp;&amp;<span style="color: rgba(0, 0, 0, 1)">永久禁用)
    swapoff </span>-a &amp;&amp; <span style="color: rgba(0, 0, 255, 1)">sed</span> -i <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/ swap / s/^\(.*\)$/#\1/g</span><span style="color: rgba(128, 0, 0, 1)">'</span> /etc/<span style="color: rgba(0, 0, 0, 1)">fstab
    setenforce </span><span style="color: rgba(128, 0, 128, 1)">0</span> &amp;&amp; <span style="color: rgba(0, 0, 255, 1)">sed</span> -i <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s/^SELINUX=.*/SELINUX=disabled/</span><span style="color: rgba(128, 0, 0, 1)">'</span> /etc/selinux/<span style="color: rgba(0, 0, 0, 1)">config

</span><span style="color: rgba(128, 0, 128, 1)">7</span><span style="color: rgba(0, 0, 0, 1)">)、调整内核参数,对于 K8S
    vim kubernetes.conf
    net.bridge.bridge</span>-nf-call-iptables=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    net.bridge.bridge</span>-nf-call-ip6tables=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    net.ipv4.ip_forward</span>=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    net.ipv4.tcp_tw_recycle</span>=<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
    # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它
    vm.swappiness</span>=<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
    # 不检查物理内存是否够用
    vm.overcommit_memory</span>=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    # 开启 OOM
    fs.inotify.max_user_instances</span>=<span style="color: rgba(128, 0, 128, 1)">8192</span><span style="color: rgba(0, 0, 0, 1)">
    vm.panic_on_oom</span>=<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
    fs.inotify.max_user_watches</span>=<span style="color: rgba(128, 0, 128, 1)">1048576</span><span style="color: rgba(0, 0, 0, 1)">
    fs.</span><span style="color: rgba(0, 0, 255, 1)">file</span>-max=<span style="color: rgba(128, 0, 128, 1)">52706963</span><span style="color: rgba(0, 0, 0, 1)">
    fs.nr_open</span>=<span style="color: rgba(128, 0, 128, 1)">52706963</span><span style="color: rgba(0, 0, 0, 1)">
    net.ipv6.conf.all.disable_ipv6</span>=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    net.netfilter.nf_conntrack_max</span>=<span style="color: rgba(128, 0, 128, 1)">2310720</span>

    <span style="color: rgba(0, 0, 255, 1)">cp</span> kubernetes.conf/etc/sysctl.d/<span style="color: rgba(0, 0, 0, 1)">kubernetes.conf

    sysctl </span>-p /etc/sysctl.d/<span style="color: rgba(0, 0, 0, 1)">kubernetes.conf


</span><span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)">)、 修改Cgroup Driver
    </span><span style="color: rgba(128, 0, 128, 1)">1</span>&gt;<span style="color: rgba(0, 0, 0, 1)">、修改daemon.json
    # vim /etc/docker/<span style="color: rgba(0, 0, 0, 1)">daemon.json
    {
      </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">registry-mirrors</span><span style="color: rgba(128, 0, 0, 1)">"</span>: [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">https://v16stybc.mirror.aliyuncs.com</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">],
      </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">exec-opts</span><span style="color: rgba(128, 0, 0, 1)">"</span>: [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">native.cgroupdriver=systemd</span><span style="color: rgba(128, 0, 0, 1)">"</span>]<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">新增这行</span>
<span style="color: rgba(0, 0, 0, 1)">    }
    </span><span style="color: rgba(128, 0, 128, 1)">2</span>&gt;<span style="color: rgba(0, 0, 0, 1)">、 重新加载docker
    # systemctl daemon-reload &amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> systemctl restart docker
   
    修改cgroupdriver是为了消除告警:
    : detected </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">cgroupfs</span><span style="color: rgba(128, 0, 0, 1)">"</span> as the Docker cgroup driver. The recommended driver is <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">systemd</span><span style="color: rgba(128, 0, 0, 1)">"</span>. Please follow the guide at https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">kubernetes.io/docs/setup/cri/</span>


<span style="color: rgba(128, 0, 128, 1)">9</span><span style="color: rgba(0, 0, 0, 1)">)、新增 k8s 源
    #vim /etc/<span style="color: rgba(0, 0, 255, 1)">yum</span>.repos.d/<span style="color: rgba(0, 0, 0, 1)">kubernetes.repo
   
    name</span>=<span style="color: rgba(0, 0, 0, 1)">Kubernetes
    baseurl</span>=http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64</span>
    enabled=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    gpgcheck</span>=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    repo_gpgcheck</span>=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
    gpgkey</span>=http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg </span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg</span>
<span style="color: rgba(0, 0, 0, 1)">
    [] 中括号中的是repository </span><span style="color: rgba(0, 0, 255, 1)">id</span><span style="color: rgba(0, 0, 0, 1)">,唯一,用来标识不同仓库
    name 仓库名称,自定义
    baseurl 仓库地址
    enable 是否启用该仓库,默认为1表示启用
    gpgcheck 是否验证从该仓库获得程序包的合法性,1为验证
    repo_gpgcheck 是否验证元数据的合法性 元数据就是程序包列表,1为验证
    gpgkey</span>=<span style="color: rgba(0, 0, 0, 1)">URL 数字签名的公钥文件所在位置,如果gpgcheck值为1,此处就需要指定gpgkey文件的位置,如果gpgcheck值为0就不需要此项了

    更新缓存
    # <span style="color: rgba(0, 0, 255, 1)">yum</span><span style="color: rgba(0, 0, 0, 1)"> clean all
    # <span style="color: rgba(0, 0, 255, 1)">yum</span> -<span style="color: rgba(0, 0, 0, 1)">y makecache


</span><span style="color: rgba(128, 0, 128, 1)">10</span>)、调整系统时区,设置系统时区为中国/<span style="color: rgba(0, 0, 0, 1)">上海
    timedatectl set</span>-timezone Asia/<span style="color: rgba(0, 0, 0, 1)">Shanghai

    将当前的 UTC 时间写入硬件时钟
    timedatectl set</span>-local-rtc <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">

    重启依赖于系统时间的服务
    systemctl restart rsyslog
    systemctl restart crond

</span><span style="color: rgba(128, 0, 128, 1)">11</span><span style="color: rgba(0, 0, 0, 1)">)、关闭系统不需要的服务
    systemctl stop postfix </span>&amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> systemctl disable postfix

</span><span style="color: rgba(128, 0, 128, 1)">12</span><span style="color: rgba(0, 0, 0, 1)">)、设置 rsyslogd 和 systemd journald
    </span><span style="color: rgba(0, 0, 255, 1)">mkdir</span> /var/log/<span style="color: rgba(0, 0, 0, 1)">journal

    持久化保存日志的目录
    </span><span style="color: rgba(0, 0, 255, 1)">mkdir</span> /etc/systemd/<span style="color: rgba(0, 0, 0, 1)">journald.conf.d

    vim </span>/etc/systemd/journald.conf.d/<span style="color: rgba(128, 0, 128, 1)">99</span>-<span style="color: rgba(0, 0, 0, 1)">prophet.conf
    Journal]
    #持久化保存到磁盘
    Storage</span>=<span style="color: rgba(0, 0, 0, 1)">persistent
    # 压缩历史日志
    Compress</span>=<span style="color: rgba(0, 0, 0, 1)">yes
    SyncIntervalSec</span>=<span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(0, 0, 0, 1)">
    mRateLimitInterval</span>=<span style="color: rgba(0, 0, 0, 1)">30s
    RateLimitBurst</span>=<span style="color: rgba(128, 0, 128, 1)">1000</span><span style="color: rgba(0, 0, 0, 1)">
    # 最大占用空间 10G
    SystemMaxUse</span>=<span style="color: rgba(0, 0, 0, 1)">10G
    # 单日志文件最大 200M
    SystemMaxFileSize</span>=<span style="color: rgba(0, 0, 0, 1)">200M
    # 日志保存时间 </span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)"> 周
    MaxRetentionSec</span>=<span style="color: rgba(0, 0, 0, 1)">2week
    # 不将日志转发到
    syslogForwardToSyslog</span>=<span style="color: rgba(0, 0, 0, 1)">no

    systemctl restart systemd</span>-<span style="color: rgba(0, 0, 0, 1)">journald

</span><span style="color: rgba(128, 0, 128, 1)">13</span>)、升级系统内核为 <span style="color: rgba(128, 0, 128, 1)">4</span>.44CentOS <span style="color: rgba(128, 0, 128, 1)">7</span><span style="color: rgba(0, 0, 0, 1)">.x
    系统自带的 </span><span style="color: rgba(128, 0, 128, 1)">3.10</span><span style="color: rgba(0, 0, 0, 1)">.x 内核存在一些 Bugs,导致运行的 Docker、Kubernetes 不稳定
    rpm </span>-Uvh http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm</span>
<span style="color: rgba(0, 0, 0, 1)">
    安装完成后检查 </span>/boot/grub2/<span style="color: rgba(0, 0, 0, 1)">grub.cfg 中对应内核 menuentry 中是否包含 initrd16 配置,如果没有,再安装一次!
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> --enablerepo=elrepo-kernel <span style="color: rgba(0, 0, 255, 1)">install</span> -y kernel-<span style="color: rgba(0, 0, 0, 1)">lt

    设置开机从新内核启动
    grub2</span>-set-default <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">CentOS Linux (4.4.189-1.el7.elrepo.x86_64) 7 (Core)</span><span style="color: rgba(128, 0, 0, 1)">'</span></pre>
</div>
<p>&nbsp;</p>
<h2>3、master&nbsp;节点安装</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">. 版本查看
# <span style="color: rgba(0, 0, 255, 1)">yum</span> list kubelet --showduplicates | <span style="color: rgba(0, 0, 255, 1)">sort</span> -<span style="color: rgba(0, 0, 0, 1)">r

</span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">. 安装kubelet、kubeadm和kubectl(不指定版本,默认用的就是最新版本)
    </span><span style="color: rgba(0, 0, 255, 1)">yum</span> <span style="color: rgba(0, 0, 255, 1)">install</span> -<span style="color: rgba(0, 0, 0, 1)">y kubelet kubeadm kubectl

    </span><span style="color: rgba(128, 0, 128, 1)">2.1</span><span style="color: rgba(0, 0, 0, 1)">.安装包说明
    kubelet 运行在集群所有节点上,用于启动Pod和容器等对象的工具
    kubeadm 用于初始化集群,启动集群的命令工具
    kubectl 用于和集群通信的命令行,通过kubectl可以部署和管理应用,查看各种资源,创建、删除和更新各种组件

    </span><span style="color: rgba(128, 0, 128, 1)">2.2</span><span style="color: rgba(0, 0, 0, 1)">.启动kubelet并设置开机启动
    # systemctl enable kubelet &amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> systemctl start kubelet

    </span><span style="color: rgba(128, 0, 128, 1)">2.3</span><span style="color: rgba(0, 0, 0, 1)">.kubelet命令补全
    ## <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/<span style="color: rgba(0, 0, 0, 1)">.bash_profile
    # source ~/<span style="color: rgba(0, 0, 0, 1)">.bash_profile


</span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">. 下载镜像
    </span><span style="color: rgba(128, 0, 128, 1)">3.1</span><span style="color: rgba(0, 0, 0, 1)"> Kubernetes几乎所有的安装组件和Docker镜像都放在goolge自己的网站上,直接访问可能会有网络问题,这里的解决办法是从阿里云镜像仓库下载镜像,拉取到本地以后改回默认的镜像tag。

    ## vim image.<span style="color: rgba(0, 0, 255, 1)">sh</span><span style="color: rgba(0, 0, 0, 1)">
    #</span>!/bin/<span style="color: rgba(0, 0, 0, 1)">bash
    url</span>=gcr.azk8s.cn/google-<span style="color: rgba(0, 0, 0, 1)">containers
    version</span>=v1.<span style="color: rgba(128, 0, 128, 1)">17.3</span><span style="color: rgba(0, 0, 0, 1)">
    images</span>=(`kubeadm config images list --kubernetes-version=$version|<span style="color: rgba(0, 0, 255, 1)">awk</span> -F <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">{print $2}</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">`)
    </span><span style="color: rgba(0, 0, 255, 1)">for</span> imagename <span style="color: rgba(0, 0, 255, 1)">in</span> ${images[@]} ; <span style="color: rgba(0, 0, 255, 1)">do</span><span style="color: rgba(0, 0, 0, 1)">
          docker pull $url</span>/<span style="color: rgba(0, 0, 0, 1)">$imagename
          docker tag $url</span>/$imagename k8s.gcr.io/<span style="color: rgba(0, 0, 0, 1)">$imagename
          docker rmi </span>-f $url/<span style="color: rgba(0, 0, 0, 1)">$imagename
    </span><span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">
   
    url为阿里云镜像仓库地址,version为安装的kubernetes版本。

    </span><span style="color: rgba(128, 0, 128, 1)">3.2</span><span style="color: rgba(0, 0, 0, 1)"> 下载镜像
    </span><span style="color: rgba(128, 0, 128, 1)">1</span>)、首先要给 image.<span style="color: rgba(0, 0, 255, 1)">sh</span><span style="color: rgba(0, 0, 0, 1)"> 赋于执行权限
    </span><span style="color: rgba(0, 0, 255, 1)">chmod</span> u+x ./image.<span style="color: rgba(0, 0, 255, 1)">sh</span>

    <span style="color: rgba(128, 0, 128, 1)">2</span>)、运行脚本image.<span style="color: rgba(0, 0, 255, 1)">sh</span><span style="color: rgba(0, 0, 0, 1)">,下载指定版本的镜像
    .</span>/image.<span style="color: rgba(0, 0, 255, 1)">sh</span>

<span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">.初始化 master
    </span><span style="color: rgba(128, 0, 128, 1)">4.1</span><span style="color: rgba(0, 0, 0, 1)"> 初始化
    # kubeadm init --apiserver-advertise-address <span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">56.2</span> --pod-network-cidr=<span style="color: rgba(128, 0, 128, 1)">10.244</span>.<span style="color: rgba(128, 0, 128, 1)">0.0</span>/<span style="color: rgba(128, 0, 128, 1)">16</span><span style="color: rgba(0, 0, 0, 1)">
    apiserver</span>-advertise-address指定master的interface,pod-network-<span style="color: rgba(0, 0, 0, 1)">cidr指定Pod网络的范围,这里使用flannel网络方案

    记录kubeadm join的输出,后面需要这个命令将各个节点加入集群中。输出大概如下的内容:
    To start using your cluster, you need to run the following as a regular user:
      </span><span style="color: rgba(0, 0, 255, 1)">mkdir</span> -p $HOME/<span style="color: rgba(0, 0, 0, 1)">.kube
      </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">cp</span> -i /etc/kubernetes/admin.conf $HOME/.kube/<span style="color: rgba(0, 0, 0, 1)">config
      </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">chown</span> $(<span style="color: rgba(0, 0, 255, 1)">id</span> -u):$(<span style="color: rgba(0, 0, 255, 1)">id</span> -g) $HOME/.kube/<span style="color: rgba(0, 0, 0, 1)">config

    You should now deploy a pod network to the cluster.
    Run </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">kubectl apply -f .yaml</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> with one of the options listed at:
      https:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">kubernetes.io/docs/concepts/cluster-administration/addons/</span>
<span style="color: rgba(0, 0, 0, 1)">
    Then you can </span><span style="color: rgba(0, 0, 255, 1)">join</span><span style="color: rgba(0, 0, 0, 1)"> any number of worker nodes by running the following on each as root:

    kubeadm </span><span style="color: rgba(0, 0, 255, 1)">join</span> <span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">56.2</span>:<span style="color: rgba(128, 0, 128, 1)">6443</span> --<span style="color: rgba(0, 0, 0, 1)">token f09fag.fohc5f0v9eb4ail5 \
      </span>--discovery-token-ca-cert-<span style="color: rgba(0, 0, 0, 1)">hash sha256:5c08d18980a8e0c251664fda92427814a02c31b152ac553b6539b5123067ce86

    </span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)"> 加载环境变量
   # <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">export KUBECONFIG=/etc/kubernetes/admin.conf</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/<span style="color: rgba(0, 0, 0, 1)">.bash_profile
    # source ~/<span style="color: rgba(0, 0, 0, 1)">.bash_profile
   
    本文所有操作都在root用户下执行,若为非root用户,则执行如下操作:
    </span><span style="color: rgba(0, 0, 255, 1)">mkdir</span> -p $HOME/<span style="color: rgba(0, 0, 0, 1)">.kube
    </span><span style="color: rgba(0, 0, 255, 1)">cp</span> -i /etc/kubernetes/admin.conf $HOME/.kube/<span style="color: rgba(0, 0, 0, 1)">config
    </span><span style="color: rgba(0, 0, 255, 1)">chown</span> $(<span style="color: rgba(0, 0, 255, 1)">id</span> -u):$(<span style="color: rgba(0, 0, 255, 1)">id</span> -g) $HOME/.kube/<span style="color: rgba(0, 0, 0, 1)">config

</span><span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(0, 0, 0, 1)">. 安装pod网络(如果此命令执行不成功,可能是文件拉取的问题,直接把这个文件下载到本地即可)
# kubectl apply -f https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">raw.githubusercontent.com/coreos/flannel/master/Documentation/</span>
kube-<span style="color: rgba(0, 0, 0, 1)">flannel.yml

下载本地后执行:(直接打开网址,复制到本地文件中)
#kubectl apply -f kube-<span style="color: rgba(0, 0, 0, 1)">flannel.yml


</span><span style="color: rgba(128, 0, 128, 1)">6</span><span style="color: rgba(0, 0, 0, 1)">. master节点配置
    taint:污点的意思。如果一个节点被打上了污点,那么pod是不允许运行在这个节点上面的

    </span><span style="color: rgba(128, 0, 128, 1)">6.1</span><span style="color: rgba(0, 0, 0, 1)"> 删除master节点默认污点
    默认情况下集群不会在master上调度pod,如果偏想在master上调度Pod,可以执行如下操作:

    查看污点:
    # kubectl describe node master|<span style="color: rgba(0, 0, 255, 1)">grep</span> -<span style="color: rgba(0, 0, 0, 1)">i taints
    Taints:             node</span>-role.kubernetes.io/<span style="color: rgba(0, 0, 0, 1)">master:NoSchedule
    删除默认污点:

    # kubectl taint nodes master node-role.kubernetes.io/master-<span style="color: rgba(0, 0, 0, 1)">
    node</span>/<span style="color: rgba(0, 0, 0, 1)">master untainted
    </span><span style="color: rgba(128, 0, 128, 1)">6.2</span><span style="color: rgba(0, 0, 0, 1)"> 污点机制
    语法
    kubectl taint node key</span>=<span style="color: rgba(0, 0, 0, 1)">value   
         其中 可取值: [ NoSchedule </span>| PreferNoSchedule |<span style="color: rgba(0, 0, 0, 1)"> NoExecute ]
          NoSchedule: 一定不能被调度
          PreferNoSchedule: 尽量不要调度
          NoExecute: 不仅不会调度, 还会驱逐Node上已有的Pod
   
    打污点
    # kubectl taint node master key1=<span style="color: rgba(0, 0, 0, 1)">value1:NoSchedule
    node</span>/<span style="color: rgba(0, 0, 0, 1)">master tainted
    # kubectl describe node master|<span style="color: rgba(0, 0, 255, 1)">grep</span> -<span style="color: rgba(0, 0, 0, 1)">i taints
    Taints:             key1</span>=<span style="color: rgba(0, 0, 0, 1)">value1:NoSchedule
    key为key1,value为value1(value可以为空),effect为NoSchedule表示一定不能被调度

    删除污点:
    # kubectl taint nodes masterkey1-<span style="color: rgba(0, 0, 0, 1)">   
    node</span>/<span style="color: rgba(0, 0, 0, 1)">master untainted
    # kubectl describe node master|<span style="color: rgba(0, 0, 255, 1)">grep</span> -<span style="color: rgba(0, 0, 0, 1)">i taints
    Taints:             </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
    删除指定key所有的effect,‘</span>-’表示移除所有以key1为键的污点</pre>
</div>
<h2>4、Node节点安装</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">)、查看令牌
# kubeadm token list
TOKEN                     TTL         EXPIRES                     USAGES                   DESCRIPTION                                                EXTRA GROUPS
dnpkej.113e5cokaq30qcra   18h         </span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">02</span>-25T12:<span style="color: rgba(128, 0, 128, 1)">12</span>:<span style="color: rgba(128, 0, 128, 1)">21</span>+<span style="color: rgba(128, 0, 128, 1)">08</span>:<span style="color: rgba(128, 0, 128, 1)">00</span>   authentication,signing   The default bootstrap token generated by <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubeadm init</span><span style="color: rgba(128, 0, 0, 1)">'</span>.   system:bootstrappers:kubeadm:default-node-<span style="color: rgba(0, 0, 0, 1)">token

</span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">)、 生成新的令牌(如果过期的话)
# kubeadm token create
dnpkej.113e5cokaq30qcra

</span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">)、 生成新的加密串
# openssl x509 -pubkey -<span style="color: rgba(0, 0, 255, 1)">in</span> /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der <span style="color: rgba(128, 0, 128, 1)">2</span>&gt;/dev/<span style="color: rgba(0, 0, 255, 1)">null</span> |<span style="color: rgba(0, 0, 0, 1)"> \
   openssl dgst </span>-sha256 -hex | <span style="color: rgba(0, 0, 255, 1)">sed</span> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s/^.* //</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
63de5412694706097a440cb9375d5e06207dfdf225579aa04b489b6470ea46c3

</span><span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">)、 node节点加入集群
在node节点上分别执行如下操作:
# kubeadm </span><span style="color: rgba(0, 0, 255, 1)">join</span> <span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">56.2</span>:<span style="color: rgba(128, 0, 128, 1)">6443</span> --token dnpkej.113e5cokaq30qcra   --discovery-token-ca-cert-hash sha256:63de5412694706097a440cb9375d5e06207dfdf225579aa04b489b6470ea46c3</pre>
</div>
<h2>5、Dashboard安装</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">. 下载yaml
# <span style="color: rgba(0, 0, 255, 1)">wget</span>https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/yeyinzhu321/Centos7.6-install-k8s-v1.14.2-cluster/blob/master/kubernetes-dashboard.yaml</span>

<span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">. 配置yaml
</span><span style="color: rgba(128, 0, 128, 1)">2.1</span><span style="color: rgba(0, 0, 0, 1)"> 修改镜像地址
</span><span style="color: rgba(0, 0, 255, 1)">sed</span> -i <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s/k8s.gcr.io/registry.cn-hangzhou.aliyuncs.com\/kuberneters/g</span><span style="color: rgba(128, 0, 0, 1)">'</span> kubernetes-<span style="color: rgba(0, 0, 0, 1)">dashboard.yaml
由于默认的镜像仓库网络访问不通,故改成阿里镜像

</span><span style="color: rgba(128, 0, 128, 1)">2.2</span><span style="color: rgba(0, 0, 0, 1)"> 外网访问
</span><span style="color: rgba(0, 0, 255, 1)">sed</span> -i <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/targetPort:/a\ \ \ \ \ \ nodePort: 30001\n\ \ type: NodePort</span><span style="color: rgba(128, 0, 0, 1)">'</span> kubernetes-<span style="color: rgba(0, 0, 0, 1)">dashboard.yaml
配置NodePort,外部通过https:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">NodeIp:NodePort 访问Dashboard,此时端口为30001</span>

<span style="color: rgba(128, 0, 128, 1)">2.3</span><span style="color: rgba(0, 0, 0, 1)"> 新增管理员帐号(在文件最后添加如下的配置)
vim kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard.yaml
</span>---<span style="color: rgba(0, 0, 0, 1)">
# </span>------------------- dashboard-admin -------------------<span style="color: rgba(0, 0, 0, 1)"> #
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard</span>-<span style="color: rgba(0, 0, 0, 1)">admin
namespace: kube</span>-<span style="color: rgba(0, 0, 0, 1)">system

</span>---<span style="color: rgba(0, 0, 0, 1)">
apiVersion: rbac.authorization.k8s.io</span>/<span style="color: rgba(0, 0, 0, 1)">v1beta1
kind: ClusterRoleBinding
metadata:
name: dashboard</span>-<span style="color: rgba(0, 0, 0, 1)">admin
subjects:
</span>-<span style="color: rgba(0, 0, 0, 1)"> kind: ServiceAccount
name: dashboard</span>-<span style="color: rgba(0, 0, 0, 1)">admin
namespace: kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster</span>-<span style="color: rgba(0, 0, 0, 1)">admin
创建超级管理员的账号用于登录Dashboard

</span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">. 部署访问
</span><span style="color: rgba(128, 0, 128, 1)">3.1</span><span style="color: rgba(0, 0, 0, 1)"> 部署Dashboard
# kubectl apply -f kubernetes-<span style="color: rgba(0, 0, 0, 1)">dashboard.yaml

</span><span style="color: rgba(128, 0, 128, 1)">3.2</span><span style="color: rgba(0, 0, 0, 1)"> 状态查看
# kubectl get deployment kubernetes-dashboard -n kube-<span style="color: rgba(0, 0, 0, 1)">system
# kubectl get pods -n kube-system -<span style="color: rgba(0, 0, 0, 1)">o wide
# kubectl get services -n kube-<span style="color: rgba(0, 0, 0, 1)">system

</span><span style="color: rgba(128, 0, 128, 1)">3.3</span><span style="color: rgba(0, 0, 0, 1)"> 令牌查看
kubectl describe secrets </span>-n kube-system dashboard-<span style="color: rgba(0, 0, 0, 1)">admin
令牌为:
eyJhbGciOiJSUzI1NiIsImtpZCI6InZDSWF3X1JBcjB6ZGFzbF9pZ0N4a0FKTEREMTFtZUJGVzlFVUJOdUNMMkEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tc21tdzkiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiYmE5MzExYzMtMDMyOC00ZTUzLTg0M2MtNjZhN2I4YzA4Njc3Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.xi7exXIYJYr1r8epqdDqajmWK_5vIqcqvNhjEkmkkOstsH5eiFdlKvyIYNm416</span>-98mD5CPYRWq4aSl1DmXYa1un6a37X0WV0bKaDDEj-oCCnFs5Sucol7sCs5IGMZ8xVRwQCYseLlPGJCuY0u3d-Fx3BtuiHlvuHKLIMEgNWHOIgcCX1bzArK7tBBQkzT6XJrwoij6NuV4cxbegTQ6WNbAAlx-m862lfzP9mcK_fM5fOvAaxePEnMMvqb8kQ4bgTmMKr2DqlS-2F4t6eiOPQx8vFZ-<span style="color: rgba(0, 0, 0, 1)">LURopOgAIC8akbbsfdnB1TJ9aaYdxqwG3BggR2mv1qEcp4dmdXKkn4tBeHnw


</span><span style="color: rgba(128, 0, 128, 1)">3.4</span> 访问 https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">NodeIp:30001</span>
Dashboard提供了可以实现集群管理、工作负载、服务发现和负载均衡、存储、字典配置、日志视图等功能。</pre>
</div>
<p>&nbsp;</p>
<h2>6、集群测试</h2>
<div class="cnblogs_code">
<pre>1<span style="color: rgba(0, 0, 0, 1)">. 部署应用
</span>1.1<span style="color: rgba(0, 0, 0, 1)"> 命令方式
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl run httpd-app --image=httpd --replicas=2</span>
<span style="color: rgba(0, 0, 0, 1)">
通过命令行方式部署apache服务

</span>1.2<span style="color: rgba(0, 0, 0, 1)"> 配置文件方式
vim nginx.yml
apiVersion: apps</span>/<span style="color: rgba(0, 0, 0, 1)">v1
kind: Deployment
metadata:
name: nginx</span>-<span style="color: rgba(0, 0, 0, 1)">demo
spec:
selector:
    matchLabels:
      app: nginx
template:
    metadata:
      labels:
      app: nginx
    spec:
      containers:
      </span>-<span style="color: rgba(0, 0, 0, 1)"> name: nginx
      image: nginx
      ports:
      </span>- containerPort: 80

---<span style="color: rgba(0, 0, 0, 1)">

apiVersion: v1
kind: Service
metadata:
name: nginx</span>-<span style="color: rgba(0, 0, 0, 1)">demo
spec:
type: NodePort
ports:
</span>-<span style="color: rgba(0, 0, 0, 1)"> name: nginx
    nodePort: </span>30000<span style="color: rgba(0, 0, 0, 1)">
    port: </span>80<span style="color: rgba(0, 0, 0, 1)">
    protocol: TCP
    targetPort: </span>80<span style="color: rgba(0, 0, 0, 1)">
selector:
    app: nginx

<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl apply -f nginx.yml </span>
deployment.extensions/<span style="color: rgba(0, 0, 0, 1)">nginx created
通过配置文件方式部署nginx服务

</span>2<span style="color: rgba(0, 0, 0, 1)">. 状态查看
</span>2.1<span style="color: rgba(0, 0, 0, 1)"> 查看节点状态
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl get nodes</span>
<span style="color: rgba(0, 0, 0, 1)">NAME         STATUS   ROLES    AGE   VERSION
k8s</span>-master01   Ready    master   5h33m   v1.17.3<span style="color: rgba(0, 0, 0, 1)">
node01         Ready    </span>&lt;none&gt;   5h32m   v1.17.3

2.2<span style="color: rgba(0, 0, 0, 1)"> 查看pod状态
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl get pod --all-namespaces</span>
<span style="color: rgba(0, 0, 0, 1)">NAMESPACE   NAME                                    READY   STATUS    RESTARTS   AGE
default       nginx</span>-demo-85ff79dd56-svdbl             1/1<span style="color: rgba(0, 0, 0, 1)">   Running   0          4h12m
kube</span>-system   coredns-6955765f44-498gl                1/1   Running   2<span style="color: rgba(0, 0, 0, 1)">          5h33m
kube</span>-system   coredns-6955765f44-5895j                1/1   Running   2<span style="color: rgba(0, 0, 0, 1)">          5h33m
kube</span>-system   etcd-k8s-master01                     1/1   Running   1<span style="color: rgba(0, 0, 0, 1)">          5h34m
kube</span>-system   kube-apiserver-k8s-master01             1/1   Running   1<span style="color: rgba(0, 0, 0, 1)">          5h34m
kube</span>-system   kube-controller-manager-k8s-master01    1/1   Running   1<span style="color: rgba(0, 0, 0, 1)">          5h34m
kube</span>-system   kube-flannel-ds-amd64-f8f44             1/1<span style="color: rgba(0, 0, 0, 1)">   Running   0          4h55m
kube</span>-system   kube-flannel-ds-amd64-krhxq             1/1<span style="color: rgba(0, 0, 0, 1)">   Running   0          4h55m
kube</span>-system   kube-proxy-9gfqq                        1/1   Running   1<span style="color: rgba(0, 0, 0, 1)">          5h33m
kube</span>-system   kube-proxy-kzlpw                        1/1<span style="color: rgba(0, 0, 0, 1)">   Running   0          5h33m
kube</span>-system   kube-scheduler-k8s-master01             1/1   Running   1<span style="color: rgba(0, 0, 0, 1)">          5h34m
kube</span>-system   kubernetes-dashboard-778ff9499c-ph44s   1/1<span style="color: rgba(0, 0, 0, 1)">   Running   0          5h21m

</span>2.3<span style="color: rgba(0, 0, 0, 1)"> 查看副本数
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl get deployments</span>
NAME         READY   UP-TO-<span style="color: rgba(0, 0, 0, 1)">DATE   AVAILABLE   AGE
nginx</span>-demo   1/1   1            1<span style="color: rgba(0, 0, 0, 1)">         4h12m

<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl get pod -o wide</span>
<span style="color: rgba(0, 0, 0, 1)">NAME                        READY   STATUS    RESTARTS   AGE   IP         NODE   NOMINATED NODE   READINESS GATES
nginx</span>-demo-85ff79dd56-svdbl   1/1   Running   0          4h13m   10.244.1.8   node01   &lt;none&gt;         &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
可以看到nginx和httpd的3个副本pod均匀分布在3个节点上

</span>2.4<span style="color: rgba(0, 0, 0, 1)"> 查看deployment详细信息
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl describe deployments</span>


2.5<span style="color: rgba(0, 0, 0, 1)"> 查看集群基本组件状态
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> kubectl get cs</span>
<span style="color: rgba(0, 0, 0, 1)">NAME               STATUS    MESSAGE             ERROR
scheduler            Healthy   ok                  
controller</span>-<span style="color: rgba(0, 0, 0, 1)">manager   Healthy   ok                  
etcd</span>-0               Healthy   {<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">health</span><span style="color: rgba(128, 0, 0, 1)">"</span>:<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">true</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">}   

</span>2.6<span style="color: rgba(0, 0, 0, 1)"> 测试
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> curl 192.168.56.3:30000       </span>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
&lt;style&gt;<span style="color: rgba(0, 0, 0, 1)">
    body {
      width: 35em;
      margin: 0 auto;
      font</span>-family: Tahoma, Verdana, Arial, sans-<span style="color: rgba(0, 0, 0, 1)">serif;
    }
</span>&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Welcome to nginx!&lt;/h1&gt;
&lt;p&gt;If you see this page, the nginx web server <span style="color: rgba(0, 0, 255, 1)">is</span> successfully installed <span style="color: rgba(0, 0, 255, 1)">and</span><span style="color: rgba(0, 0, 0, 1)">
working. Further configuration </span><span style="color: rgba(0, 0, 255, 1)">is</span> required.&lt;/p&gt;

&lt;p&gt;For online documentation <span style="color: rgba(0, 0, 255, 1)">and</span><span style="color: rgba(0, 0, 0, 1)"> support please refer to
</span>&lt;a href=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http://nginx.org/</span><span style="color: rgba(128, 0, 0, 1)">"</span>&gt;nginx.org&lt;/a&gt;.&lt;br/&gt;<span style="color: rgba(0, 0, 0, 1)">
Commercial support </span><span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> available at
</span>&lt;a href=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http://nginx.com/</span><span style="color: rgba(128, 0, 0, 1)">"</span>&gt;nginx.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you <span style="color: rgba(0, 0, 255, 1)">for</span> using nginx.&lt;/em&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<p>&nbsp;浏览器访问如下:</p>
<p><img src="https://img2018.cnblogs.com/i-beta/974873/202002/974873-20200224175128178-758555841.png" alt="" width="454" height="200"></p>
<p>&nbsp;</p>
<h2>7、 报错总结</h2>
<p>1)、image.sh 脚本做一下补充</p>
<p>  1&gt;、url 已经做了修改,按照文中的 url 我下载的时候下载不了,超时,所以我已经改为可以下载的 url 了</p>
<p>  2&gt;、version 一定要改为自己的版本</p>
<p>2)、<span style="font-size: 18px"><strong>安装pod网络</strong></span>时 apply 的时候,那个文件一直超时,如果这样可以直接下载此文件即可</p>
<p>&nbsp;</p>
<p>3)、如果 kubeadm init apply 的时候提示 xxx folder exist,执行如下的语句</p>
<p>  kubeadm reset&nbsp;</p>
<p>4)、集群测试的时候 nginx.yaml&nbsp;中如果apiVersion&nbsp;写的是 extension/v1beta1&nbsp;的话,会报错.改为如下的即可</p>
<div class="cnblogs_code">
<pre>apiVersion: apps/<span style="color: rgba(0, 0, 0, 1)">v1
kind: Deployment
metadata:
name: nginx</span>-<span style="color: rgba(0, 0, 0, 1)">demo
spec:
selector:
    matchLabels:
      app: nginx
template:
    metadata:
      labels:
      app: nginx
    spec:
      containers:
      </span>-<span style="color: rgba(0, 0, 0, 1)"> name: nginx
      image: nginx
      ports:
      </span>- containerPort: 80
---<span style="color: rgba(0, 0, 0, 1)">
apiVersion: v1
kind: Service
metadata:
name: nginx</span>-<span style="color: rgba(0, 0, 0, 1)">demo
spec:
type: NodePort
ports:
</span>-<span style="color: rgba(0, 0, 0, 1)"> name: nginx
    nodePort: </span>30000<span style="color: rgba(0, 0, 0, 1)">
    port: </span>80<span style="color: rgba(0, 0, 0, 1)">
    protocol: TCP
    targetPort: </span>80<span style="color: rgba(0, 0, 0, 1)">
selector:
    app: nginx</span></pre>
</div><br><br>
来源:https://www.cnblogs.com/zhuzi91/p/12357971.html
頁: [1]
查看完整版本: centos 7 安装 kubernetes