http://blog.csdn.net/Qguanri/article/details/50925672
K8S 分为 master 和 slave 两类角色。
环境说明如下表:
对象 | 版本 | IP | 备注 |
---|---|---|---|
k8s-master | centos7 | XX.XX.XX.179 | K8S的master所在主机 |
etcd-server | centos7 | XX.XX.XX.179 | etcd服务所在主机,与master在同一机器 |
k8s-slave | centos7 | XX.XX.XX.182 | K8S节点所在主机 |
更新yum
登录 k8s-master 主机
<code class="hljs sql has-numbering">yum <span class="hljs-operator"><span class="hljs-keyword">update</span> -y</span></code><ul style="" class="pre-numbering"><li>1</li></ul><ul style="" class="pre-numbering"><li>1</li></ul>
创建yum源
注意:k8s-master,k8s-slave都要按照以下操作创建yum源
登录master/slave主机:
<code class="hljs lasso has-numbering">vi virt7<span class="hljs-attribute">-docker</span><span class="hljs-attribute">-common</span><span class="hljs-attribute">-release</span><span class="hljs-built_in">.</span>repo</code><ul style="" class="pre-numbering"><li>1</li></ul><ul style="" class="pre-numbering"><li>1</li></ul>
加入以下内容:
<code class="hljs ini has-numbering"><span class="hljs-title">[virt7-docker-common-release]</span>
<span class="hljs-setting">name=<span class="hljs-value">virt7-docker-common-release</span></span>
<span class="hljs-setting">baseurl=<span class="hljs-value">http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/</span></span>
<span class="hljs-setting">gpgcheck=<span class="hljs-value"><span class="hljs-number">0</span></span></span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li></ul>
安装服务
执行以下命令,安装kubernetes和etcd。
<code class="hljs lasso has-numbering">yum <span class="hljs-attribute">-y</span> install <span class="hljs-subst">--</span>enablerepo<span class="hljs-subst">=</span>virt7<span class="hljs-attribute">-docker</span><span class="hljs-attribute">-common</span><span class="hljs-attribute">-release</span> kubernetes etcd</code><ul style="" class="pre-numbering"><li>1</li></ul><ul style="" class="pre-numbering"><li>1</li></ul>
1.修改文件/etc/kubernetes/config(所有节点)
注意,master和slave主机都要修改
指定master主机的ip,文件内容如下:
<code class="hljs ruby has-numbering"><span class="hljs-variable">$ </span>cat /etc/kubernetes/config
<span class="hljs-constant">KUBE_LOGTOSTDERR</span>=<span class="hljs-string">"--logtostderr=true"</span>
<span class="hljs-constant">KUBE_LOG_LEVEL</span>=<span class="hljs-string">"--v=0"</span>
<span class="hljs-constant">KUBE_ALLOW_PRIV</span>=<span class="hljs-string">"--allow-privileged=false"</span>
<span class="hljs-constant">KUBE_MASTER</span>=<span class="hljs-string">"--master=http://XX.XX.XX.179:8080"</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>
禁用防火墙
<code class="hljs lasso has-numbering">systemctl disable iptables<span class="hljs-attribute">-services</span> firewalld
systemctl stop iptables<span class="hljs-attribute">-services</span> firewalld</code><ul style="" class="pre-numbering"><li>1</li><li>2</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li></ul>
在master节点配置kubernetes服务
1.修改配置文件/etc/etcd/etcd.conf,确保etcd监听所有地址。内容如下:
<code class="hljs haskell has-numbering">$ cat /etc/etcd/etcd.conf
<span class="hljs-type">ETCD_NAME</span>=<span class="hljs-default"><span class="hljs-keyword">default</span></span>
<span class="hljs-type">ETCD_DATA_DIR</span>=<span class="hljs-string">"/var/lib/etcd/default.etcd"</span>
<span class="hljs-type">ETCD_LISTEN_CLIENT_URLS</span>=<span class="hljs-string">"http://0.0.0.0:2379"</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li></ul>
2.修改配置文件/etc/kubernetes/apiserver
<code class="hljs bash has-numbering">cat /etc/kubernetes/apiserver
KUBE_API_ADDRESS=<span class="hljs-string">"--address=0.0.0.0"</span>
KUBE_API_PORT=<span class="hljs-string">"--port=8080"</span>
KUBELET_PORT=<span class="hljs-string">"--kubelet-port=10250"</span>
KUBE_ETCD_SERVERS=<span class="hljs-string">"--etcd-servers=http://127.0.0.1:2379"</span>
KUBE_SERVICE_ADDRESSES=<span class="hljs-string">"--service-cluster-ip-range=10.254.0.0/16"</span>
KUBE_ADMISSION_CONTROL=<span class="hljs-string">"--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"</span>
KUBE_API_ARGS=<span class="hljs-string">""</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li></ul>
3.修改配置文件/etc/kubernetes/controller-manager,定义slave主机ip地址
<code class="hljs ini has-numbering"><span class="hljs-setting">KUBELET_ADDRESSES=<span class="hljs-value"><span class="hljs-string">"--machines=XX.XX.XX.182"</span></span></span></code><ul style="" class="pre-numbering"><li>1</li></ul><ul style="" class="pre-numbering"><li>1</li></ul>
在master主机上,启动服务
执行如下命令,批量启动服务
<code class="hljs lasso has-numbering">for SERVICES <span class="hljs-keyword">in</span> etcd kube<span class="hljs-attribute">-apiserver</span> kube<span class="hljs-attribute">-controller</span><span class="hljs-attribute">-manager</span> kube<span class="hljs-attribute">-scheduler</span>; <span class="hljs-keyword">do</span>
systemctl restart <span class="hljs-variable">$SERVICES</span>
systemctl enable <span class="hljs-variable">$SERVICES</span>
systemctl status <span class="hljs-variable">$SERVICES</span>
done</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>
slave节点配置
注意:slave节点主机,要安装Docker,docker版本1.7以上
yum 安装kubernetes
<code class="hljs lasso has-numbering">yum <span class="hljs-attribute">-y</span> install <span class="hljs-subst">--</span>enablerepo<span class="hljs-subst">=</span>virt7<span class="hljs-attribute">-docker</span><span class="hljs-attribute">-common</span><span class="hljs-attribute">-release</span> kubernetes flannel</code><ul style="" class="pre-numbering"><li>1</li></ul><ul style="" class="pre-numbering"><li>1</li></ul>
1.修改kubernetes配置文件,指定master。
<code class="hljs ruby has-numbering"><span class="hljs-variable">$ </span>cat /etc/kubernetes/config
<span class="hljs-constant">KUBE_MASTER</span>=<span class="hljs-string">"--master=http://XX.XX.XX.179:8080"</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li></ul>
2.配置kubelet服务。
<code class="hljs ruby has-numbering"><span class="hljs-variable">$ </span>cat /etc/kubernetes/kubelet
<span class="hljs-constant">KUBELET_ADDRESS</span>=<span class="hljs-string">"--address=0.0.0.0"</span>
<span class="hljs-constant">KUBELET_PORT</span>=<span class="hljs-string">"--port=10250"</span>
<span class="hljs-constant">KUBELET_HOSTNAME</span>=<span class="hljs-string">"--hostname-override=XX.XX.XX.182"</span>
<span class="hljs-constant">KUBELET_API_SERVER</span>=<span class="hljs-string">"--api-servers=http://XX.XX.XX.179:8080"</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>
在slave主机上,启动服务
<code class="hljs bash has-numbering"><span class="hljs-keyword">for</span> SERVICES <span class="hljs-keyword">in</span> kube-proxy kubelet docker flanneld; <span class="hljs-keyword">do</span>
systemctl restart <span class="hljs-variable">$SERVICES</span>
systemctl enable <span class="hljs-variable">$SERVICES</span>
systemctl status <span class="hljs-variable">$SERVICES</span>
<span class="hljs-keyword">done</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>
验证
现在登陆master,确认slave的状态
<code class="hljs avrasm has-numbering">$ kubectl get nodes
NAME LABELS STATUS AGE
<span class="hljs-number">10.16</span><span class="hljs-number">.93</span><span class="hljs-number">.182</span> kubernetes<span class="hljs-preprocessor">.io</span>/hostname=XX<span class="hljs-preprocessor">.XX</span><span class="hljs-preprocessor">.XX</span><span class="hljs-number">.182</span> Ready <span class="hljs-number">1</span>h</code>