K8s部署
本文介绍使用 K8s 来部署 Apache ShenYu 网关。
目录
一. 使用 h2 作为数据库
- 创建 Namespace和 ConfigMap
- 部署 shenyu-admin
- 部署 shenyu-bootstrap 二. 使用 MySQL 作为数据库
和 h2 过程类似,需要注意的两个地方
- 需要加载 mysql-connector.jar,所以需要一个文件存储的地方
- 需要指定外部 MySQL 数据库配置,通过 Endpoints 来代理外部 MySQL 数据库
具体流程如下:
- 创建 Namespace和 ConfigMap
- 创建 Endpoints 代理外部 MySQL
- 创建 PV 存储 mysql-connector.jar
- 部署 shenyu-admin
- 部署 shenyu-bootstrap
一. 使用 h2 作为数据库
1. 创建 Namespace 和 ConfigMap
- 创建文件 shenyu-ns.yaml
apiVersion: v1
kind: Namespace
metadata:
name: shenyu
labels:
name: shenyu
---
apiVersion: v1
kind: ConfigMap
metadata:
name: shenyu-cm
namespace: shenyu
data:
application-local.yml: |
server:
port: 9195
address: 0.0.0.0
spring:
main:
allow-bean-definition-overriding: true
application:
name: shenyu-bootstrap
management:
health:
defaults:
enabled: false
shenyu:
local:
enabled: true
file:
enabled: true
cross:
enabled: true
dubbo:
parameter: multi
sync:
websocket:
urls: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095/websocket
exclude:
enabled: false
paths:
- /favicon.ico
extPlugin:
enabled: true
threads: 1
scheduleTime: 300
scheduleDelay: 30
scheduler:
enabled: false
type: fixed
threads: 16
logging:
level:
root: info
org.springframework.boot: info
org.apache.ibatis: info
org.apache.shenyu.bonuspoint: info
org.apache.shenyu.lottery: info
org.apache.shenyu: info
- 执行
kubectl apply -f shenyu-ns.yaml
2. 部署 shenyu-admin
- 创建文件 shenyu-admin.yaml
# 示例使用 nodeport 方式暴露端口
apiVersion: v1
kind: Service
metadata:
namespace: shenyu
name: shenyu-admin-svc
spec:
selector:
app: shenyu-admin
type: NodePort
ports:
- protocol: TCP
port: 9095
targetPort: 9095
nodePort: 31095
---
# shenyu-admin
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: shenyu
name: shenyu-admin
spec:
selector:
matchLabels:
app: shenyu-admin
replicas: 1
template:
metadata:
labels:
app: shenyu-admin
spec:
containers:
- name: shenyu-admin
image: apache/shenyu-admin:2.4.0
imagePullPolicy: Always
ports:
- containerPort: 9095
env:
- name: 'TZ'
value: 'Asia/Beijing'
- 执行
kubectl apply -f shenyu-ns.yaml
3. 部署 shenyu-bootstrap
- 创建文件 shenyu-bootstrap.yaml
# 示例使用 nodeport 方式暴露端口
apiVersion: v1
kind: Service
metadata:
namespace: shenyu
name: shenyu-bootstrap-svc
spec:
selector:
app: shenyu-bootstrap
type: NodePort
ports:
- protocol: TCP
port: 9195
targetPort: 9195
nodePort: 31195
---
# shenyu-bootstrap
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: shenyu
name: shenyu-bootstrap
spec:
selector:
matchLabels:
app: shenyu-bootstrap
replicas: 1
template:
metadata:
labels:
app: shenyu-bootstrap
spec:
volumes:
- name: shenyu-bootstrap-config
configMap:
name: shenyu-cm
items:
- key: application-local.yml
path: application-local.yml
containers:
- name: shenyu-bootstrap
image: apache/shenyu-bootstrap:2.4.0
ports:
- containerPort: 9195
env:
- name: TZ
value: Asia/Beijing
volumeMounts:
- name: shenyu-bootstrap-config
mountPath: /opt/shenyu-bootstrap/conf/application-local.yml
subPath: application-local.yml
- 执行
kubectl apply -f shenyu-bootstrap.yaml