kubeadm部署Kubernetes(k8s)完整版详细教程
<p style="margin-left: 0"> </p><p style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">kubeadm</span><span style="color: rgba(51, 51, 51, 1)">是官方社区推出的一个用于快速部署</span><span style="color: rgba(51, 51, 51, 1)">kubernetes</span><span style="color: rgba(51, 51, 51, 1)">集群的工具。</span></strong></p>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">这个工具能通过两条指令完成一个</span><span style="color: rgba(51, 51, 51, 1)">kubernetes</span><span style="color: rgba(51, 51, 51, 1)">集群的部署:</span></p>
<pre class="has"><code class="language-bash"># 创建一个 Master 节点
$ kubeadm init
# 将一个 Node 节点加入到当前集群中
$ kubeadm join <Master节点的IP和端口 >
</code></pre>
<p><img alt="" class="has" src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly91cGxvYWQtaW1hZ2VzLmppYW5zaHUuaW8vdXBsb2FkX2ltYWdlcy82NTM0ODg3LWFkNThjYTMzOWM0MDNhNGIucG5n?x-oss-process=image/format,png"></p>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">1. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">安装要求</span></strong></h1>
</div>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">在开始之前,部署</span><span style="color: rgba(51, 51, 51, 1)">Kubernetes</span><span style="color: rgba(51, 51, 51, 1)">集群机器需要满足以下几个条件:</span></p>
<ul><li><span style="color: rgba(51, 51, 51, 1)">一台或多台机器,操作系统</span><span style="color: rgba(51, 51, 51, 1)"> CentOS7.x-86_x64</span></li>
<li><span style="color: rgba(51, 51, 51, 1)">硬件配置:</span><span style="color: rgba(51, 51, 51, 1)">2GB</span><span style="color: rgba(51, 51, 51, 1)">或更多</span><span style="color: rgba(51, 51, 51, 1)">RAM</span><span style="color: rgba(51, 51, 51, 1)">,</span><span style="color: rgba(51, 51, 51, 1)">2</span><span style="color: rgba(51, 51, 51, 1)">个</span><span style="color: rgba(51, 51, 51, 1)">CPU</span><span style="color: rgba(51, 51, 51, 1)">或更多</span><span style="color: rgba(51, 51, 51, 1)">CPU</span><span style="color: rgba(51, 51, 51, 1)">,硬盘</span><span style="color: rgba(51, 51, 51, 1)">30GB</span><span style="color: rgba(51, 51, 51, 1)">或更多</span></li>
<li><span style="color: rgba(51, 51, 51, 1)">集群中所有机器之间网络互通</span></li>
<li><span style="color: rgba(51, 51, 51, 1)">可以访问外网,需要拉取镜像</span></li>
<li><span style="color: rgba(51, 51, 51, 1)">禁止</span><span style="color: rgba(51, 51, 51, 1)">swap</span><span style="color: rgba(51, 51, 51, 1)">分区</span></li>
</ul><h2><strong>环境:</strong></h2>
<p>master 192.168.116.129【最低是2核的,不然安装会保存】</p>
<p>node1 192.168.116.130</p>
<p>node2 192.168.116.131</p>
<p><img alt="" class="has" height="298" src="https://img-blog.csdnimg.cn/20200108134510529.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="743"></p>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">2. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">学习目标</span></strong></h1>
<ol><li><strong><span style="color: rgba(51, 51, 51, 1)">在所有节点上安装</span><span style="color: rgba(51, 51, 51, 1)">Docker</span><span style="color: rgba(51, 51, 51, 1)">和</span><span style="color: rgba(51, 51, 51, 1)">kubeadm</span></strong></li>
<li><strong><span style="color: rgba(51, 51, 51, 1)">部署</span><span style="color: rgba(51, 51, 51, 1)">Kubernetes Master</span></strong></li>
<li><strong><span style="color: rgba(51, 51, 51, 1)">部署容器网络插件</span></strong></li>
<li><strong><span style="color: rgba(51, 51, 51, 1)">部署</span><span style="color: rgba(51, 51, 51, 1)"> Kubernetes Node</span><span style="color: rgba(51, 51, 51, 1)">,将节点加入</span><span style="color: rgba(51, 51, 51, 1)">Kubernetes</span><span style="color: rgba(51, 51, 51, 1)">集群中</span></strong></li>
<li><strong><span style="color: rgba(51, 51, 51, 1)">部署</span><span style="color: rgba(51, 51, 51, 1)">Dashboard Web</span><span style="color: rgba(51, 51, 51, 1)">页面,可视化查看</span><span style="color: rgba(51, 51, 51, 1)">Kubernetes</span><span style="color: rgba(51, 51, 51, 1)">资源</span></strong></li>
</ol></div>
<p> </p>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">3. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">准备环境</span></strong></h1>
</div>
<p><strong><span style="color: rgba(51, 51, 51, 1)">1、关闭防火墙:</span></strong></p>
<pre class="has"><code class="language-bash">systemctl stop firewalld
systemctl disable firewalld
</code></pre>
<p><strong>2、<span style="color: rgba(51, 51, 51, 1)">关闭</span><span style="color: rgba(51, 51, 51, 1)">selinux</span><span style="color: rgba(51, 51, 51, 1)">:</span></strong></p>
<pre class="has"><code class="language-bash"> sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
</code></pre>
<p><strong>3、<span style="color: rgba(51, 51, 51, 1)">关闭</span><span style="color: rgba(51, 51, 51, 1)">swap</span><span style="color: rgba(51, 51, 51, 1)">:</span></strong></p>
<pre class="has"><code class="language-bash">swapoff -a # 临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab#永久关闭</code></pre>
<p><strong>4、修改主机名称</strong></p>
<pre class="has"><code class="language-bash">hostnamectl set-hostname 名字</code></pre>
<p><strong><span style="color: rgba(51, 51, 51, 1)">5、添加主机名与</span><span style="color: rgba(51, 51, 51, 1)">IP</span><span style="color: rgba(51, 51, 51, 1)">对应关系(记得设置主机名):</span></strong></p>
<pre class="has"><code class="language-bash">cat /etc/hosts
192.168.116.129 master
192.168.116.130 note1
192.168.116.131 note2
</code></pre>
<p><strong>6、<span style="color: rgba(51, 51, 51, 1)">将桥接的</span><span style="color: rgba(51, 51, 51, 1)">IPv4</span><span style="color: rgba(51, 51, 51, 1)">流量传递到</span><span style="color: rgba(51, 51, 51, 1)">iptables</span><span style="color: rgba(51, 51, 51, 1)">的链</span></strong></p>
<pre class="has"><code class="language-bash"> cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
</code></pre>
<pre class="has"><code> sysctl --system</code></pre>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">4. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">所有节点安装</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">Docker/kubeadm/kubelet</span></strong></h1>
<p><span style="color: rgba(243, 59, 69, 1)"><strong>xshell可以使用发送键盘所有会话来安装。比较省事</strong></span></p>
<p><img alt="" class="has" height="113" src="https://img-blog.csdnimg.cn/20200108135752343.png" width="635"></p>
<p><img alt="" class="has" height="157" src="https://img-blog.csdnimg.cn/20200108135728432.png" width="1149"></p>
</div>
<p style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">Kubernetes</span><span style="color: rgba(51, 51, 51, 1)">默认</span><span style="color: rgba(51, 51, 51, 1)">CRI</span><span style="color: rgba(51, 51, 51, 1)">(容器运行时)为</span><span style="color: rgba(51, 51, 51, 1)">Docker</span><span style="color: rgba(51, 51, 51, 1)">,因此先安装</span><span style="color: rgba(51, 51, 51, 1)">Docker</span><span style="color: rgba(51, 51, 51, 1)">。</span></strong></p>
<h2><strong>1、<span style="color: rgba(51, 51, 51, 1)">安装Docker</span></strong></h2>
<p><strong><span style="color: rgba(51, 51, 51, 1)">安装Docker源</span></strong></p>
<pre class="has"><code class="language-bash">yum install -y wget && wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
</code></pre>
<p><strong>安装Docker</strong></p>
<pre class="has"><code class="language-bash">yum -y install docker-ce-18.06.1.ce-3.el7</code></pre>
<p><strong>开启自启和启动</strong></p>
<pre class="has"><code>systemctl enable docker && systemctl start docker</code></pre>
<p><strong>查看版本</strong></p>
<pre class="has"><code class="language-bash">docker --version
</code></pre>
<h2>2、<strong> </strong><strong><span style="color: rgba(51, 51, 51, 1)">安装</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">kubeadm</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">,</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">kubelet</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">和</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">kubectl</span></strong></h2>
<p><strong><span style="color: rgba(51, 51, 51, 1)">1、添加阿里云</span><span style="color: rgba(51, 51, 51, 1)">YUM的</span><span style="color: rgba(51, 51, 51, 1)">软件源</span></strong></p>
<pre class="has"><code class="language-bash">cat > /etc/yum.repos.d/kubernetes.repo << EOF
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
</code></pre>
<p style="margin-left: 0">2、<strong><span style="color: rgba(51, 51, 51, 1)">安装</span><span style="color: rgba(51, 51, 51, 1)">kubeadm</span><span style="color: rgba(51, 51, 51, 1)">,</span><span style="color: rgba(51, 51, 51, 1)">kubelet</span><span style="color: rgba(51, 51, 51, 1)">和</span><span style="color: rgba(51, 51, 51, 1)">kubectl</span></strong></p>
<p style="margin-left: 0"><span style="color: rgba(243, 59, 69, 1)"><strong>由于版本更新频繁,这里指定版本号部署:</strong></span></p>
<pre class="has"><code>yum install -y kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0</code></pre>
<p><strong>设置开机自启</strong></p>
<pre class="has"><code>systemctl enable kubelet</code></pre>
<h1>5、<strong><span style="color: rgba(51, 51, 51, 1)">部署</span><span style="color: rgba(51, 51, 51, 1)">Kubernetes Master</span></strong></h1>
<p><span style="color: rgba(51, 51, 51, 1)">在</span><span style="color: rgba(51, 51, 51, 1)">192.168.116.129</span><span style="color: rgba(51, 51, 51, 1)">(</span><span style="color: rgba(51, 51, 51, 1)">Master</span><span style="color: rgba(51, 51, 51, 1)">)执行</span></p>
<pre class="has"><code class="language-bash">kubeadm init \
--apiserver-advertise-address=192.168.116.129 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.15.0 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
</code></pre>
<p><img alt="" class="has" height="260" src="https://img-blog.csdnimg.cn/2020010814064484.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="1085"></p>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">由于默认拉取镜像地址</span><span style="color: rgba(51, 51, 51, 1)">k8s.gcr.io</span><span style="color: rgba(51, 51, 51, 1)">国内无法访问,这里指定阿里云镜像仓库地址。</span></p>
<p style="margin-left: 0"><img alt="" class="has" height="290" src="https://img-blog.csdnimg.cn/20200108140759201.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="1151"></p>
<p><strong>已经初始化完成</strong><img alt="" class="has" height="324" src="https://img-blog.csdnimg.cn/20200108140916701.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="1100"></p>
<p style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">使用</span><span style="color: rgba(51, 51, 51, 1)">kubectl</span><span style="color: rgba(51, 51, 51, 1)">工具:</span></strong></p>
<pre class="has"><code class="language-bash">mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
</code></pre>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">6. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">安装</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">Pod</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">网络插件(</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">CNI</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">)</span></strong></h1>
<pre class="has"><code>kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml</code></pre>
<p><span style="color: rgba(51, 51, 51, 1)">确保能够访问到</span><span style="color: rgba(51, 51, 51, 1)">quay.io</span><span style="color: rgba(51, 51, 51, 1)">这个</span><span style="color: rgba(51, 51, 51, 1)">registery</span><span style="color: rgba(51, 51, 51, 1)">。</span></p>
<p><span style="color: rgba(51, 51, 51, 1)">如果下载失败,可以改成这个镜像地址:</span><span style="color: rgba(51, 51, 51, 1)">lizhenliang/flannel:v0.11.0-amd64</span></p>
<p>也可以使用我给配置文件 https://www.lanzous.com/i8jjpij</p>
<p>这里,我是用的是我的配置文件。</p>
<p><img alt="" class="has" height="169" src="https://img-blog.csdnimg.cn/20200108141405260.png" width="486"></p>
<pre class="has"><code>kubectl apply -f kube-flannel.yml</code></pre>
<p><img alt="" class="has" height="353" src="https://img-blog.csdnimg.cn/20200108141559390.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="574"></p>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">7. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">加入</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">Kubernetes Node</span></strong></h1>
<p><strong><span style="color: rgba(51, 51, 51, 1)">在node上安装flannel</span></strong></p>
<pre class="has"><code>docker pull lizhenliang/flannel:v0.11.0-amd64
</code></pre>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">在</span><span style="color: rgba(51, 51, 51, 1)">192.168.116.130</span><span style="color: rgba(51, 51, 51, 1)">(</span><span style="color: rgba(51, 51, 51, 1)">Node</span><span style="color: rgba(51, 51, 51, 1)">)执行。</span></p>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">向集群添加新节点,执行在</span><span style="color: rgba(51, 51, 51, 1)">kubeadm init</span><span style="color: rgba(51, 51, 51, 1)">输出的</span><span style="color: rgba(51, 51, 51, 1)">kubeadm join</span><span style="color: rgba(51, 51, 51, 1)">命令:</span></p>
</div>
<pre class="has"><code>kubeadm join 192.168.116.129:6443 --token iz96vy.f5ukew9geeome5is \
--discovery-token-ca-cert-hash sha256:72b689426bfc34512294c29b39ea3b2af3a94e39f62c4434f3a49f16d51a1382 </code></pre>
<p><img alt="" class="has" height="569" src="https://img-blog.csdnimg.cn/20200108142415759.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="1081"></p>
<p>查看Node</p>
<pre class="has"><code> kubectl get node
</code></pre>
<p><img alt="" class="has" height="174" src="https://img-blog.csdnimg.cn/20200108151656809.png" width="517"></p>
<p>添加一下node2,命令如上。切记,先执行<span style="color: rgba(243, 59, 69, 1)"><strong>在node上安装flannel</strong></span></p>
<p><img alt="" class="has" height="100" src="https://img-blog.csdnimg.cn/2020010815181254.png" width="405"></p>
<p>已经完全准备完成。</p>
<pre class="has"><code>kubectl get pods -n kube-system
</code></pre>
<p><img alt="" class="has" height="390" src="https://img-blog.csdnimg.cn/20200108152313199.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="648"></p>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">8. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">测试</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">kubernetes</span></strong><strong><span style="color: rgba(51, 51, 51, 1)">集群</span></strong></h1>
</div>
<p style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">在</span><span style="color: rgba(51, 51, 51, 1)">Kubernetes</span><span style="color: rgba(51, 51, 51, 1)">集群中创建一个</span><span style="color: rgba(51, 51, 51, 1)">pod</span><span style="color: rgba(51, 51, 51, 1)">,验证是否正常运行:</span></strong></p>
<p><strong>创建nginx容器</strong></p>
<pre class="has"><code> kubectl create deployment nginx --image=nginx</code></pre>
<p><strong>暴露对外端口</strong></p>
<pre class="has"><code> kubectl expose deployment nginx --port=80 --type=NodePort</code></pre>
<p><strong>查看nginx是否运行成功</strong></p>
<pre class="has"><code> kubectl get pod,svc</code></pre>
<p><img alt="" class="has" height="158" src="https://img-blog.csdnimg.cn/20200108152607842.png" width="704"></p>
<p>在浏览器访问。三个结点都可访问,说明集群已经搭建完成,</p>
<p><img alt="" class="has" height="312" src="https://img-blog.csdnimg.cn/20200108152655274.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="787"></p>
<p><img alt="" class="has" height="339" src="https://img-blog.csdnimg.cn/20200108152708610.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="741"></p>
<p><img alt="" class="has" height="360" src="https://img-blog.csdnimg.cn/20200108152722680.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="795"></p>
<p> </p>
<p>扩容nginx副本wei3个,成功</p>
<pre class="has"><code>kubectl scale deployment nginx --replicas=3
</code></pre>
<p><img alt="" class="has" height="120" src="https://img-blog.csdnimg.cn/20200108153234116.png" width="571"></p>
<pre class="has"><code>kubectl get pods
</code></pre>
<p><img alt="" class="has" height="191" src="https://img-blog.csdnimg.cn/20200108153617737.png" width="509"></p>
<p> </p>
<div>
<h1 style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">9. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">部署</span></strong><strong><span style="color: rgba(51, 51, 51, 1)"> Dashboard</span></strong></h1>
</div>
<p>先前已经给配置配置文件。</p>
<p>也可以使用我给配置文件 https://www.lanzous.com/i8jjpij</p>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">默认镜像国内无法访问,修改镜像地址为:</span><span style="color: rgba(51, 51, 51, 1)"> lizhenliang/kubernetes-dashboard-amd64:v1.10.1</span></p>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">默认</span><span style="color: rgba(51, 51, 51, 1)">Dashboard</span><span style="color: rgba(51, 51, 51, 1)">只能集群内部访问,修改</span><span style="color: rgba(51, 51, 51, 1)">Service</span><span style="color: rgba(51, 51, 51, 1)">为</span><span style="color: rgba(51, 51, 51, 1)">NodePort</span><span style="color: rgba(51, 51, 51, 1)">类型,暴露到外部:</span></p>
<p><img alt="" class="has" height="303" src="https://img-blog.csdnimg.cn/20200108153956631.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="593"></p>
<p><strong>先Docker拉去镜像</strong></p>
<pre class="has"><code>docker pulllizhenliang/kubernetes-dashboard-amd64:v1.10.1
</code></pre>
<p><strong>执行kubernetes-dashboard.yaml 文件</strong></p>
<pre class="has"><code> kubectl apply -f kubernetes-dashboard.yaml </code></pre>
<p><strong>安装成功</strong></p>
<p><img alt="" class="has" height="176" src="https://img-blog.csdnimg.cn/2020010815404548.png" width="635"></p>
<p><strong>查看暴露的端口</strong></p>
<pre class="has"><code class="language-bash">kubectl get pods,svc -n kube-system
</code></pre>
<p><img alt="" class="has" height="356" src="https://img-blog.csdnimg.cn/20200108164453386.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="861"></p>
<p> </p>
<h1><strong><span style="color: rgba(51, 51, 51, 1)">10. </span></strong><strong><span style="color: rgba(51, 51, 51, 1)">访问</span></strong><strong><span style="color: rgba(51, 51, 51, 1)"> Dashboard的web界面</span></strong></h1>
<p style="margin-left: 0"><span style="color: rgba(51, 51, 51, 1)">访问地址:</span><u><span style="color: rgba(65, 131, 196, 1)">https://NodeIP:30001 【</span><span style="color: rgba(243, 59, 69, 1)">必须是https</span><span style="color: rgba(65, 131, 196, 1)">】</span></u></p>
<p style="margin-left: 0"><img alt="" class="has" height="860" src="https://img-blog.csdnimg.cn/20200108164554291.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="1200"></p>
<p> </p>
<p style="margin-left: 0"><strong><span style="color: rgba(51, 51, 51, 1)">创建</span><span style="color: rgba(51, 51, 51, 1)">service account</span><span style="color: rgba(51, 51, 51, 1)">并绑定默认</span><span style="color: rgba(51, 51, 51, 1)">cluster-admin</span><span style="color: rgba(51, 51, 51, 1)">管理员集群角色:【依次执行】</span></strong></p>
<pre class="has"><code>kubectl create serviceaccount dashboard-admin -n kube-system</code></pre>
<pre class="has"><code> kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin</code></pre>
<pre class="has"><code> kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')</code></pre>
<p><img alt="" class="has" height="418" src="https://img-blog.csdnimg.cn/20200108164747779.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="1079"></p>
<p>已经部署完成。</p>
<p><img alt="" class="has" height="1048" src="https://img-blog.csdnimg.cn/20200108164833885.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlaWFuXzk5,size_16,color_FFFFFF,t_70" width="1200"></p>
<p> </p>
</div>
</div>
<div id="MySignature" role="contentinfo">
人生得意须尽欢,莫使金樽空对月。 天生我材必有用,千金散尽还复来。<br><br>
来源:https://www.cnblogs.com/heian99/p/12173599.html
頁:
[1]