Kuboard实战

This commit is contained in:
huanqing.shao
2019-08-22 22:19:17 +08:00
parent 41d17c53ae
commit 481070dba1
20 changed files with 329 additions and 17 deletions

View File

@ -0,0 +1,135 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kuboard
namespace: kube-system
annotations:
k8s.eip.work/displayName: kuboard
k8s.eip.work/ingress: "true"
k8s.eip.work/service: NodePort
k8s.eip.work/workload: kuboard
labels:
k8s.eip.work/layer: monitor
k8s.eip.work/name: kuboard
spec:
replicas: 1
selector:
matchLabels:
k8s.eip.work/layer: monitor
k8s.eip.work/name: kuboard
template:
metadata:
labels:
k8s.eip.work/layer: monitor
k8s.eip.work/name: kuboard
spec:
containers:
- name: kuboard
image: eipwork/kuboard:latest
imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: kuboard
namespace: kube-system
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
nodePort: 32567
selector:
k8s.eip.work/layer: monitor
k8s.eip.work/name: kuboard
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kuboard-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kuboard-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kuboard-user
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kuboard-viewer
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kuboard-viewer
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: view
subjects:
- kind: ServiceAccount
name: kuboard-viewer
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kuboard-viewer-node
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:node
subjects:
- kind: ServiceAccount
name: kuboard-viewer
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kuboard-viewer-pvp
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:persistent-volume-provisioner
subjects:
- kind: ServiceAccount
name: kuboard-viewer
namespace: kube-system
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: kuboard
namespace: kube-system
annotations:
nginx.org/websocket-services: "kuboard"
nginx.com/sticky-cookie-services: "serviceName=kuboard srv_id expires=1h path=/"
spec:
rules:
- host: kuboard.yourdomain.com
http:
paths:
- path: /
backend:
serviceName: kuboard
servicePort: http

View File

@ -33,7 +33,7 @@
> 如果您参考 https://kuboard.cn 网站上提供的 Kubernetes 安装文档,可在 master 节点上执行以下命令。
``` sh
kubectl apply -f https://raw.githubusercontent.com/eip-work/eip-monitor-repository/master/dashboard/kuboard.yaml
kubectl apply -f https://kuboard.cn/install-script/kuboard.yaml
```
:::
@ -43,12 +43,10 @@ kubectl apply -f https://raw.githubusercontent.com/eip-work/eip-monitor-reposito
卸载 Kuboard
``` sh
kubectl delete -f https://raw.githubusercontent.com/eip-work/eip-monitor-repository/master/dashboard/kuboard.yaml
kubectl delete -f https://kuboard.cn/install-script/kuboard.yaml
```
:::
::::
## 获取 Token

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

View File

@ -1,10 +1,15 @@
# 部署第一个应用程序
本文翻译自 Kubernetes 官网 [Using kubectl to Create a Deployment](https://kubernetes.io/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro/) ,并有所改写
### 前提
假设您已经完成 Kubernetes 集群的安装,请参考文档 [安装 Kubernetes 单Master节点](/install/install-k8s)
假设您已经
* 完成 Kubernetes 集群的安装,请参考文档 [安装 Kubernetes 单Master节点](/install/install-k8s.html)
* 完成 Kuboard 的安装,请参考文档 [安装 Kuboard](/install/install-dashboard.html)
### 目标
@ -38,6 +43,15 @@ Deployment 处于 master 节点上,通过发布 Deploymentmaster 节点会
## 实战:部署 nginx Deployment
本套教程提供了两种实战方式:
* 使用 kubectl
* 使用 Kuboard
:::: tabs type:border-card
::: tab 使用kubectl lazy
**创建 YAML 文件**
创建文件 nginx-deployment.yaml内容如下
@ -64,9 +78,7 @@ spec: #这是关于该Deployment的描述可以理解为你期待该D
spec: #期望Pod实现的功能即在pod中部署
containers: #生成container与docker中的container是同一种
- name: nginx #container的名称
image: nginx:1.7.9 #使用镜像nginx:1.7.9创建container并向外暴露80端口
ports:
- containerPort: 80
image: nginx:1.7.9 #使用镜像nginx:1.7.9创建container该container默认80端口可访问
```
</template>
@ -92,8 +104,6 @@ spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
```
</template>
@ -116,6 +126,53 @@ kubectl get deployments
kubectl get pods
```
:::
::: tab 使用Kuboard lazy
**打开 Kuboard 集群概览界面**,如下图所示:
![image-20190822165220992](./deploy-app.assets/image-20190822165220992.png)
**点击 default 名称空间**
![image-20190822165351264](./deploy-app.assets/image-20190822165351264.png)
点击 **创建工作负载**
并填写表单如下:
| 字段名 | 填写内容 | 备注 |
| -------- | ----------- | ------------------------------------------------------- |
| 服务类型 | Deployment | |
| 服务分层 | 展现层 | Kuboard使用这个字段确定将部署显示在微服务架构的哪个分层 |
| 服务名称 | nginx | 服务分层的前缀 + 服务名 组成最终的 K8S Deployment name |
| 服务描述 | Nginx部署 | 显示在微服务分层架构图中便于识别的名字,可以是中文 |
| 副本数量 | 1 | replicas |
| 容器名称 | nginx | |
| 镜像 | nginx:1.7.9 | |
| 抓取策略 | Always | 每次创建 Pod 都尝试抓取镜像 |
![image-20190822171013606](./deploy-app.assets/image-20190822171013606.png)
点击 ***保存***
点击 ***应用***
点击 ***完成***
此时可查看到该应用的部署结果
:::
::::
可分别查看到一个名为 nginx-deployment 的 Deployment 和一个名为 nginx-deployment-xxxxxxx 的 Pod

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 KiB

View File

@ -48,7 +48,11 @@ Pod容器组总是在 **Node节点** 上运行。Node节点
- 容器运行环境如Docker负责下载镜像、创建和运行容器等。
## 实战:使用Kubectl进行故障排除
## 实战:故障排除
:::: tabs type:border-card
::: tab 使用kubectl lazy
在[部署第一个应用程序](./deploy-app.html) 中,我们使用了 kubectl 命令行界面部署了 nginx 并且查看了 Deployment 和 Pod。kubectl 还有如下四个常用命令,在我们排查问题时可以提供帮助:
@ -99,6 +103,24 @@ Pod容器组总是在 **Node节点** 上运行。Node节点
请尝试在您的集群中执行一下上述的几个命令,了解如何通过 kubectl 操作 kubernetes 集群中的 Node、Pod、Container。
:::
::: tab 使用Kuboard lazy
**在名称空间中查看部署**
![image-20190822172329141](./explore.assets/image-20190822172329141.png)
**查看部署及其容器组**
![image-20190822172457417](./explore.assets/image-20190822172457417.png)
:::
::::
::: tip
Worker节点是k8s中的工作计算机可能是VM或物理计算机具体取决于群集。多个Pod可以在一个节点上运行。
:::

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -65,6 +65,10 @@ Labels标签可以在创建 Kubernetes 对象时附加上去,也可以
## 实战:为您的 nginx Deployment 创建一个 Service
:::: tabs type:border-card
::: tab 使用kubectl lazy
创建nginx的Deployment中定义了Labels如下
``` yaml
@ -149,6 +153,38 @@ curl <任意节点的 IP>:32600
```
> 如果您的集群在云上,您可能通过云服务商的安全组开放 32600 端口的访问
:::
::: tab 使用Kuboard lazy
* 在 default 名称空间 点击 ***展现层 --> Nginx部署***
* 点击 ***编辑*** 按钮
* 填写表单如下:
访问方式 Service 选择 ***NodePortVPC内访问***
填写一条记录:
| 协议 | 服务端口 | 节点端口 | 容器端口 |
| ---- | -------- | -------- | -------- |
| TCP | 80 | 32601 | 80 |
如下图所示:
![image-20190822211807469](./expose.assets/image-20190822211807469.png)
* 点击 **保存**
* **访问服务**
在浏览器打开 `http://<任意节点的 IP>:32601`
:::
::::
~~到目前为止,我们已经成功部署好项目,并能够对其进行访问,

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@ -33,6 +33,10 @@ spec:
## 实战:将 nginx Deployment 扩容到 4 个副本
:::: tabs type:border-card
::: tab 使用kubectl lazy
**修改 nginx-deployment.yaml 文件**
将 replicas 修改为 4
@ -73,6 +77,30 @@ kubectl apply -f nginx-deployment.yaml
watch kubectl get pods -o wide
```
:::
::: tab 使用Kuboard
* 在 default 名称空间 点击 ***展现层 --> Nginx部署***
* 点击 ***伸缩*** 按钮
填写表单
副本数: 4
![image-20190822213532132](./scale.assets/image-20190822213532132.png)
* 点击 ***确定*** 按钮
等待新增的容器组完成初始化,如下图所示:
![image-20190822213709967](./scale.assets/image-20190822213709967.png)
:::
::::
~~一旦运行了多个应用程序实例,就可以在不停机的情况下执行滚动更新了,
~~lets go-> [执行滚动更新](./update.html)

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

View File

@ -18,21 +18,21 @@
1. 原本 Service A 将流量负载均衡到 4 个旧版本的 Pod (当中的容器为 绿色)上
![img](./update.assets/module_06_rollingupdates1.svg)
<img src="./update.assets/module_06_rollingupdates1.svg" style="border: 1px solid #d7dae2; max-width: 600px;"></img>
2. 更新完 Deployment 部署文件中的镜像版本后master 节点选择了一个 worker 节点,并根据新的镜像版本创建 Pod紫色容器。新 Pod 拥有唯一的新的 IP。同时master 节点选择一个旧版本的 Pod 将其移除。
此时Service A 将新 Pod 纳入到负载均衡中将旧Pod移除
![img](./update.assets/module_06_rollingupdates2.svg)
<img src="./update.assets/module_06_rollingupdates2.svg" style="border: 1px solid #d7dae2; max-width: 600px;"></img>
3. 同步骤2再创建一个新的 Pod 替换一个原有的 Pod
![img](./update.assets/module_06_rollingupdates3.svg)
<img src="./update.assets/module_06_rollingupdates3.svg" style="border: 1px solid #d7dae2; max-width: 600px;"></img>
1. 如此 Rolling Update 滚动更新,直到所有旧版本 Pod 均移除,新版本 Pod 也达到 Deployment 部署文件中定义的副本数,则滚动更新完成
![img](./update.assets/module_06_rollingupdates4.svg)
<img src="./update.assets/module_06_rollingupdates4.svg" style="border: 1px solid #d7dae2; max-width: 600px;"></img>
滚动更新允许以下操作:
@ -42,6 +42,10 @@
## 实战:更新 nginx Deployment
:::: tabs type:border-card
::: tab 使用kubectl lazy
**修改 nginx-deployment.yaml 文件**
修改文件中 image 镜像的标签,如下所示
@ -83,6 +87,36 @@ kubectl apply -f nginx-deployment.yaml
watch kubectl get pods -l app=nginx
```
:::
::: tab 使用Kuboard lazy
* **进入 default 名称空间**
* 点击 ***调整镜像版本***
勾选展现层,并刷新,可找到 ***Nginx部署***
* 针对 ***Nginx部署*** 点击修改
填写新的 nginx 版本号: 1.8 如下图所示:
![image-20190822214324429](./update.assets/image-20190822214324429.png)
* 点击 ***变更***
* 点击 ***应用***
* 点击 ***完成***
可观察到 Kubernetes 对 ***Nginx部署*** 执行滚动更新的过程,如下图所示
![image-20190822214503847](./update.assets/image-20190822214503847.png)
:::
::::
~~哈哈,到此,您已经成入门 kubernetes并完成了部署、扩容与滚动更新的实践

View File

@ -1,4 +1,4 @@
## v1.0.2-beta.1
## v1.0.2-beta.2
**发布日期**
@ -10,7 +10,9 @@
**优化**
* 优化删除确认的输入内容的提示
**BUG 修复**
* 修复自定义 Kubernetes DNS Domain 时,无法使用监控套件的问题
* 更新版本后,版本号显示仍然为旧版本,需要强制刷新才能显示新版本
* 重复打开预览 YAML 的窗口YAML 内容会不断累加