导入工作负载

This commit is contained in:
Shao Huan Qing
2021-10-07 18:17:19 +08:00
parent 1debcb9fbf
commit fe7c075a2b
15 changed files with 495 additions and 1 deletions

View File

@ -410,7 +410,15 @@ let sidebar = {
children: [ children: [
'k8s-advanced/ts/application', 'k8s-advanced/ts/application',
'k8s-advanced/ts/cluster', 'k8s-advanced/ts/cluster',
'k8s-advanced/ts/deployment' 'k8s-advanced/ts/deployment',
{
title: 'KuboardProxy',
collapsable: true,
children: [
'k8s-advanced/proxy/',
'k8s-advanced/proxy/rebase',
]
}
] ]
}, },
{ {
@ -503,6 +511,7 @@ let sidebar = {
title: '实战', title: '实战',
collapsable: true, collapsable: true,
children: [ children: [
'k8s-practice/import/import',
'k8s-practice/gpu/gpu', 'k8s-practice/gpu/gpu',
'k8s-practice/access/port-forward', 'k8s-practice/access/port-forward',
'k8s-practice/admin/list-images', 'k8s-practice/admin/list-images',

View File

@ -0,0 +1,363 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: example
name: cloud-eureka
annotations:
k8s.kuboard.cn/workload: cloud-eureka
k8s.kuboard.cn/displayName: 服务注册
k8s.kuboard.cn/service: ClusterIP
k8s.kuboard.cn/ingress: 'true'
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka
spec:
selector:
matchLabels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka
template:
metadata:
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka
spec:
imagePullSecrets:
- {}
initContainers: []
containers:
- image: 'swr.cn-east-2.myhuaweicloud.com/kuboard-dependency/example-cloud-eureka:v1.0.0-alpha.1'
imagePullPolicy: Always
name: cloud-eureka
volumeMounts: []
resources: {}
env:
- name: CLOUD_EUREKA_DEFAULT_ZONE
value: 'http://cloud-eureka-0:9200/eureka'
volumes: []
replicas: 1
volumeClaimTemplates: []
serviceName: cloud-eureka
---
apiVersion: v1
kind: Service
metadata:
namespace: example
name: cloud-eureka
annotations:
k8s.kuboard.cn/workload: cloud-eureka
k8s.kuboard.cn/displayName: 服务注册
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka
spec:
selector:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka
type: ClusterIP
ports:
- port: 9200
targetPort: 9200
protocol: TCP
name: mtfsyi
nodePort: 0
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
namespace: example
name: cloud-eureka
annotations:
k8s.kuboard.cn/workload: cloud-eureka
k8s.kuboard.cn/displayName: 服务注册
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka
spec:
rules:
- host: cloud-eureka.example.demo.kuboard.cn
http:
paths:
- path: /
backend:
serviceName: cloud-eureka
servicePort: mtfsyi
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: example
name: db-example
annotations:
k8s.kuboard.cn/workload: db-example
k8s.kuboard.cn/displayName: db-example
k8s.kuboard.cn/service: ClusterIP
k8s.kuboard.cn/ingress: 'false'
labels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: db-example
spec:
selector:
matchLabels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: db-example
template:
metadata:
labels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: db-example
spec:
imagePullSecrets:
- {}
initContainers: []
containers:
- image: 'swr.cn-east-2.myhuaweicloud.com/kuboard-dependency/example-db-example:v1.0.0-alpha.1'
imagePullPolicy: Always
name: db-example
volumeMounts:
- name: db-example-storage
mountPath: /var/lib/mysql
subPath: mysql
resources: {}
env:
- name: MYSQL_ROOT_PASSWORD
value: 'soqjdke4#es'
volumes:
- name: db-example-storage
persistentVolumeClaim:
claimName: db-example-storage
replicas: 1
---
apiVersion: v1
kind: Service
metadata:
namespace: example
name: db-example
annotations:
k8s.kuboard.cn/workload: db-example
k8s.kuboard.cn/displayName: db-example
labels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: db-example
spec:
selector:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: db-example
type: ClusterIP
ports:
- port: 3306
targetPort: 3306
protocol: TCP
name: fp6ksw
nodePort: 0
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: example
name: gateway-example
annotations:
k8s.kuboard.cn/workload: gateway-example
k8s.kuboard.cn/displayName: gateway-example
k8s.kuboard.cn/service: ClusterIP
k8s.kuboard.cn/ingress: 'false'
labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-example
spec:
selector:
matchLabels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-example
template:
metadata:
labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-example
spec:
imagePullSecrets:
- {}
initContainers: []
containers:
- image: 'swr.cn-east-2.myhuaweicloud.com/kuboard-dependency/example-gateway-example:v1.0.0-alpha.1'
imagePullPolicy: Always
name: gateway-example
volumeMounts: []
resources: {}
env:
- name: CLOUD_EUREKA_DEFAULT_ZONE
value: 'http://cloud-eureka:9200/eureka'
- name: SPRING_PROFILES_ACTIVE
value: example
volumes: []
replicas: 1
---
apiVersion: v1
kind: Service
metadata:
namespace: example
name: gateway-example
annotations:
k8s.kuboard.cn/workload: gateway-example
k8s.kuboard.cn/displayName: gateway-example
labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-example
spec:
selector:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-example
type: ClusterIP
ports:
- port: 9201
targetPort: 9201
protocol: TCP
name: pdmd3y
nodePort: 0
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: example
name: svc-example
annotations:
k8s.kuboard.cn/workload: svc-example
k8s.kuboard.cn/displayName: svc-example
k8s.kuboard.cn/service: none
k8s.kuboard.cn/ingress: 'false'
labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-example
spec:
selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-example
template:
metadata:
labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-example
spec:
imagePullSecrets:
- {}
initContainers: []
containers:
- image: 'swr.cn-east-2.myhuaweicloud.com/kuboard-dependency/example-svc-example:v1.0.0-alpha.1'
imagePullPolicy: Always
name: svc-example
volumeMounts: []
resources: {}
env:
- name: CLOUD_EUREKA_DEFAULT_ZONE
value: 'http://cloud-eureka:9200/eureka'
- name: DB_EXAMPLE_URL
value: >-
jdbc:mysql://db-example:3306/eip_db_example?characterEncoding=utf8&useSSL=false
- name: DB_EXAMPLE_USERNAME
value: eip_user
- name: DB_EXAMPLE_PASSWORD
value: 1qaz2wsx
- name: snowflake.dataCenterId
value: '1'
- name: csp.sentinel.dashboard.server
value: monitor-sentinel
volumes: []
replicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: example
name: web-example
annotations:
k8s.kuboard.cn/workload: web-example
k8s.kuboard.cn/displayName: web-example
k8s.kuboard.cn/service: ClusterIP
k8s.kuboard.cn/ingress: 'true'
labels:
k8s.kuboard.cn/layer: web
k8s.kuboard.cn/name: web-example
spec:
selector:
matchLabels:
k8s.kuboard.cn/layer: web
k8s.kuboard.cn/name: web-example
template:
metadata:
labels:
k8s.kuboard.cn/layer: web
k8s.kuboard.cn/name: web-example
spec:
imagePullSecrets:
- {}
initContainers: []
containers:
- command:
- nginx
- '-g'
- daemon off;
image: 'swr.cn-east-2.myhuaweicloud.com/kuboard-dependency/example-web-example:v1.0.0-alpha.1'
imagePullPolicy: Always
name: web-example
volumeMounts: []
resources: {}
env: []
volumes: []
replicas: 1
---
apiVersion: v1
kind: Service
metadata:
namespace: example
name: web-example
annotations:
k8s.kuboard.cn/workload: web-example
k8s.kuboard.cn/displayName: web-example
labels:
k8s.kuboard.cn/layer: web
k8s.kuboard.cn/name: web-example
spec:
ports:
- name: mawfrp
nodePort: 30090
port: 80
protocol: TCP
targetPort: 80
selector:
k8s.kuboard.cn/layer: web
k8s.kuboard.cn/name: web-example
type: NodePort
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
namespace: example
name: web-example
annotations:
k8s.kuboard.cn/workload: web-example
k8s.kuboard.cn/displayName: we-example
labels:
k8s.kuboard.cn/layer: web
k8s.kuboard.cn/name: web-example
spec:
rules:
- host: web-example.example.demo.kuboard.cn
http:
paths:
- path: /
backend:
serviceName: web-example
servicePort: mawfrp

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

View File

@ -0,0 +1,122 @@
---
layout: LearningLayout
description: 通过Kuboard将一个预先定义好的SpringCloud微服务样例程序导入到Kubernetes中。
---
# 导入 example 微服务
<AdSenseTitle/>
## 前提
必须具备如下条件:
* Kubernetes 集群
* 导入 example 微服务时,要求 Kubernetes 集群版本不低于 1.14.0 <Badge type="error">重要</Badge>
* 已经安装 [Kuboard v3](/install/v3/install.html)
* 集群中存在有效的存储类,如果没有请参考 [创建存储类](/learning/k8s-intermediate/persistent/nfs.html#在kuboard中创建-nfs-存储类)
## 创建名称空间
创建新的名称空间,用来导入 example。在 Kuboard 的集群页面菜单中,导航到 `名称空间-选择` 菜单,如图所示:
![创建名称空间](./import.assets/import-01-create-ns.png)
## 导入 example
* 下载 <a :href="$withBase('/kuboard_example_v3.yaml')" download="kuboard_example.yaml">kuboard_example.yaml</a> 文件
* 在完成 `example` 名称空间的创建以后,导航到菜单项 `名称空间` --> `example` --> `常用操作` --> `导入工作负载`,如下图所示:
![Kubernetes教程在Kuboard中导入工作负载](./import.assets/import-02-import-page.png)
* 点击 ***上传文件*** 按钮
并选择刚才下载的 `kuboard_example.yaml` 文件,如下图所示:
* 图中将标注此文件中可导入对象的类型及个数;
* `依赖镜像` 中的 `替换镜像标签` 选项,可以方便您在离线环境下进行导入。
![Kubernetes教程在Kuboard中导入工作负载-上传文件](./import.assets/import-03-upload.png)
* 点击 ***下一步***
默认选择所有的工作负载,如下图所示:
![Kubernetes教程在Kuboard中导入工作负载-选择所有工作负载](./import.assets/import-04-select.png)
* 点击 ***下一步***
为存储卷声明 `db-example-storage` 选择合适的存储类,如下图所示:
| 字段名称 | 填写内容 | 说明 |
| ------------------ | ------------------ | ------------------------------------------------------------ |
| 数据卷类型 | db-example-storage | NFS容器组直连NFS<br />存储卷声明:容器组使用存储卷声明 |
| 是否新建存储卷声明 | 创建新存储卷声明 | 使用已有存储卷声明:可以使用事先创建好的存储卷声明<br />创建新存储卷声明:可以创建新存储卷声明 |
| 分配模式 | 动态分配 | |
| 读写模式 | 可被多节点读写 | 只能被单节点读写、可被多节点只读、可被多节点读写 |
| 总量 | 2Gi | 2Gi代表 2G空间 |
![Kubernetes教程在Kuboard中导入工作负载-选择要存储类](./import.assets/import-05-pvc.png)
* 点击 ***下一步***
默认没有需要调整的 NodePort
![Kubernetes教程在Kuboard中导入工作负载-选择所有Secrets](./import.assets/import-06-nodeport.png)
* 点击 ***下一步***
填写新的 Ingress 域名,如下图所示:
| 字段名称 | 填写内容 | 说明 |
| ---------------- | ---------------------------------- | ------------------------------------------------------------ |
| cloud-eureka域名 | cloud-eureka.example.demo.kuboard.cn | 使用您自己的域名,<br />在测试环境建议使用如下域名格式:<br />workloadname.namespace-name.cluster-name.domain.com<br />该域名应该解析到您worker节点的外网地址或者worker 节点 80/443 端口对应负载均衡服务器的外网地址。 |
| web-example | web-example.example.demo.eip | |
![Kubernetes教程在Kuboard中导入工作负载-填写存储卷声明参数](./import.assets/import-07-ingress.png)
* 点击 ***下一步***
![Kubernetes教程在Kuboard中导入工作负载-核对信息](./import.assets/import-08-confirm.png)
* 点击 ***确定***
![Kubernetes教程在Kuboard中导入工作负载-确定](./import.assets/import-09-ok.png)
* 完成导入
在界面提示下,点击 ***应用***、 ***确定***,完成 `example` 应用的最终导入。
* 点击 ***已完成***
可在名称空间概览页中查看到刚才导入的 example 的所有工作负载,如下图所示:
![Kubernetes教程在Kuboard中导入工作负载-查看导入结果](./import.assets/import-10-ns.png)
## 验证 web-example
* 点击工作负载 ***web-example***
切换到 ***服务*** 标签页,可以看到该服务公布了 30090 这个节点端口,如下图所示:
![Kubernetes教程在Kuboard中导入工作负载-查看导入的web-example](./import.assets/import-11-nodeport.png)
* 在浏览器地址栏中输入 `http://任意节点IP:30090`,将打开如下页面:
**Example 部署成功**
![Kubernetes教程在Kuboard中导入工作负载-查看日志](./import.assets/import-12-web.png)
::tada:: ::tada:: ::tada::