<div class="preview-main">
<p> <br></p>
<p> <img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-b8a9aab5ddc6ee0305a6f66449bb86dc.png" title=""></p>
<p> <br></p>
<p> <img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-0a52baaebe389117eeb63ff9ece2ba19.png" title=""></p>
<p> k8s的部署有多种方式,但我们采用kubeadm工具部署。 <br></p>
<p> kubeadm官方地址:https://github.com/kubernetes/kubeadm </p>
<h1> 一、环境 </h1>
<p> master,etcd: 172.16.1.100 <br></p>
<p> node1: 172.16.1.101 <br></p>
<p> node2: 172.16.1.102 <br></p>
<p> k8s版本:1.11 <br></p>
<h1> 二、前提 </h1>
<p> 1、基于主机名通信:/etc/hosts; </p>
<pre class="blockcode"><code class="language-css">
172.16.1.100 master
172.16.1.101 node01
172.16.1.102 node02
</code></pre>
<p> 2、时间同步; <br></p>
<p> 3、关闭firewalld和iptables.service,这两个一定要禁用,因为k8s会自己设置iptables网络策略等; <br></p>
<pre class="blockcode"><code class="language-css">
systemctl stop iptables.service
systemctl disable iptables.service
systemctl stop firewalld.service
systemctl disable firewalld.service
</code></pre>
<p> <br></p>
<p> 4、网络桥接全部设置为1 <br></p>
<pre class="blockcode"><code class="language-cpp">
[root@k8s-master yum.repos.d]# cat /proc/sys/net/bridge/bridge-nf-call-ip6tables
1
[root@k8s-master yum.repos.d]# cat /proc/sys/net/bridge/bridge-nf-call-iptables
1
</code></pre>
<h1> 三、安装配置步骤 </h1>
<h2> 1、下载k8s安装包 </h2>
<p> 下载kubernetes包: <a href="https://github.com/kubernetes/kubernetes/releases"> https://github.com/kubernetes/kubernetes/releases </a> </p>
<p> <img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-fde3d1bf89910daf95ef5f4cfe3c67a3.png" title=""></p>
<p> <img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-566e35ca114f2df83665ab72d472b6c1.png" title=""></p>
<p> <br></p>
<p> 我们为了方便,不使用上面安装包的来安装k8s,这里只是让大家了解一下。我们此次安装使用kubeadm方式安装。 </p>
<h2> 2、准备好yum源(master和nodes都需要) <br></h2>
<p> a) docker源 </p>
<pre class="blockcode"><code class="language-css">
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
</code></pre>
<p> b)k8s源 </p>
<pre class="blockcode"><code class="language-css">
[root@k8s-master yum.repos.d]# cat k8s.repo
[k8s]
name=k8s repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1
</code></pre>
<pre class="blockcode"><code class="language-css">
[root@k8s-master yum.repos.d]# yum repolist
</code></pre>
<pre class="blockcode"><code class="language-css">
[root@k8s-master yum.repos.d]# wget https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
[root@k8s-master yum.repos.d]# rpm --import yum-key.gpg
</code></pre>
<pre class="blockcode"><code class="language-css">
[root@k8s-master yum.repos.d]# wget https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
[root@k8s-master yum.repos.d]# rpm --import rpm-package-key.gpg
</code></pre>
<h2> 3、首先安装kublete、kubeadm、docker(在master上执行) <br></h2>
<pre class="blockcode"><code class="language-css">
yum -y install docker-ce kubelet kubeadm kubectl (master上执行)
</code></pre>
<pre class="blockcode"><code class="language-css">
[root@k8s-master yum.repos.d]# rpm -ql kubelet
/etc/kubernetes/manifests #清单目录
/etc/sysconfig/kubelet #配置文件
/etc/systemd/system/kubelet.service
/usr/bin/kubelet #主程序
</code></pre>
<h2> 4、安装代理(为了翻墙) </h2>
<p> <span style="color:rgb(61,70,77);font-family:'-apple-system', 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif;"> 由于中国某种不可描述的原因,需要更改docker 默认拉取镜像的源 </span> </p>
<pre class="blockcode"><code class="language-css">
root@k8s-master yum.repos.d]# vim /usr/lib/systemd/system/docker.service
[Service]
#表示访问https服务时,通过下面的代理来访问,本次这么做的目的是为了能访问外国的docer镜像,要不会被墙,用完了再注释掉,从而继续使用国内
的镜像
Environment="HTTPS_PROXY=http://www.ik8s.io:10080"
Environment="NO_PROXY=127.0.0.0/8,172.16.0.0/16"
</code></pre>
<pre class="blockcode"><code class="language-css">
[root@k8s-master yum.repos.d]# systemctl daemon-reload
[root@k8s-master yum.repos.d]# systemctl start docker
</code></pre>
<pre class="blockcode"><code class="language-css">
[root@k8s-master yum.repos.d]# docker info #能看到如下两个
HTTPS Proxy: http://www.ik8s.io:10080
No Proxy: 127.0.0.0/8,172.16.0.0/16
</code></pre>
<pre class="blockcode"><code class="language-css">
[chenzx@sa ~]$ telnet www.ik8s.io 10080 #要确保这个端口是通的
</code></pre>
<h2> 5、运行kubeadm int初始化集群&# |
|