K8s部署

本文介绍使用 K8s 来部署 Apache ShenYu 网关。

目录

示例一. 使用 h2 作为数据库

  1. 1. 创建 Namespace ConfigMap
  2. 2. 部署 shenyu-admin
  3. 3. 部署 shenyu-bootstrap

示例二. 使用 MySQL 作为数据库

和 h2 过程类似,需要额外注意的两个地方:

  1. 1. 需要下载 mysql-connector.jar,容器启动时会执行下载命令
  2. 2. 需要指定外部 MySQL 数据库配置

具体流程如下:

  1. 1. 创建 Namespace ConfigMap
  2. 2. 部署 shenyu-admin
  3. 3. 部署 shenyu-bootstrap

示例一:使用 h2 作为数据库

1. 创建 Namespace 和 ConfigMap

创建 Namespace 和网关用到的配置文件

  • 创建文件 shenyu-ns.yaml
  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4. name: shenyu
  5. labels:
  6. name: shenyu
  7. ---
  8. apiVersion: v1
  9. kind: ConfigMap
  10. metadata:
  11. name: shenyu-cm
  12. namespace: shenyu
  13. data:
  14. shenyu-admin-application.yml: |
  15. server:
  16. port: 9095
  17. address: 0.0.0.0
  18. spring:
  19. profiles:
  20. active: h2
  21. thymeleaf:
  22. cache: true
  23. encoding: utf-8
  24. enabled: true
  25. prefix: classpath:/static/
  26. suffix: .html
  27. mvc:
  28. pathmatch:
  29. matching-strategy: ant_path_matcher
  30. mybatis:
  31. config-location: classpath:/mybatis/mybatis-config.xml
  32. mapper-locations: classpath:/mappers/*.xml
  33. shenyu:
  34. register:
  35. registerType: http #http #zookeeper #etcd #nacos #consul
  36. serverLists: #localhost:2181 #http://localhost:2379 #localhost:8848
  37. props:
  38. sessionTimeout: 5000
  39. connectionTimeout: 2000
  40. checked: true
  41. zombieCheckTimes: 5
  42. scheduledTime: 10
  43. nacosNameSpace: ShenyuRegisterCenter
  44. sync:
  45. websocket:
  46. enabled: true
  47. messageMaxSize: 10240
  48. allowOrigins: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095;ws://shenyu-bootstrap-svc.shenyu.svc.cluster.local:9195;
  49. ldap:
  50. enabled: false
  51. url: ldap://xxxx:xxx
  52. bind-dn: cn=xxx,dc=xxx,dc=xxx
  53. password: xxxx
  54. base-dn: ou=xxx,dc=xxx,dc=xxx
  55. object-class: person
  56. login-field: cn
  57. jwt:
  58. expired-seconds: 86400000
  59. shiro:
  60. white-list:
  61. - /
  62. - /favicon.*
  63. - /static/**
  64. - /index**
  65. - /platform/login
  66. - /websocket
  67. - /error
  68. - /actuator/health
  69. - /swagger-ui.html
  70. - /webjars/**
  71. - /swagger-resources/**
  72. - /v2/api-docs
  73. - /csrf
  74. swagger:
  75. enable: true
  76. apidoc:
  77. gatewayUrl: http://127.0.0.1:9195
  78. envProps:
  79. - envLabel: Test environment
  80. addressLabel: Request Address
  81. addressUrl: http://127.0.0.1:9195
  82. - envLabel: Prod environment
  83. addressLabel: Request Address
  84. addressUrl: http://127.0.0.1:9195
  85. logging:
  86. level:
  87. root: info
  88. org.springframework.boot: info
  89. org.apache.ibatis: info
  90. org.apache.shenyu.bonuspoint: info
  91. org.apache.shenyu.lottery: info
  92. org.apache.shenyu: info
  93. shenyu-admin-application-h2.yml: |
  94. shenyu:
  95. database:
  96. dialect: h2
  97. init_script: "sql-script/h2/schema.sql"
  98. init_enable: true
  99. spring:
  100. datasource:
  101. url: jdbc:h2:mem:~/shenyu;DB_CLOSE_DELAY=-1;MODE=MySQL;
  102. username: sa
  103. password: sa
  104. driver-class-name: org.h2.Driver
  105. shenyu-bootstrap-application.yml: |
  106. server:
  107. port: 9195
  108. address: 0.0.0.0
  109. spring:
  110. main:
  111. allow-bean-definition-overriding: true
  112. allow-circular-references: true
  113. application:
  114. name: shenyu-bootstrap
  115. codec:
  116. max-in-memory-size: 2MB
  117. cloud:
  118. discovery:
  119. enabled: false
  120. nacos:
  121. discovery:
  122. server-addr: 127.0.0.1:8848 # Spring Cloud Alibaba Dubbo use this.
  123. enabled: false
  124. namespace: ShenyuRegisterCenter
  125. eureka:
  126. client:
  127. enabled: false
  128. serviceUrl:
  129. defaultZone: http://localhost:8761/eureka/
  130. instance:
  131. prefer-ip-address: true
  132. management:
  133. health:
  134. defaults:
  135. enabled: false
  136. shenyu:
  137. matchCache:
  138. selector:
  139. selectorEnabled: false
  140. initialCapacity: 10000 # initial capacity in cache
  141. maximumSize: 10000 # max size in cache
  142. rule:
  143. initialCapacity: 10000 # initial capacity in cache
  144. maximumSize: 10000 # max size in cache
  145. trie:
  146. childrenSize: 10000
  147. pathVariableSize: 1000
  148. pathRuleCacheSize: 1000
  149. matchMode: antPathMatch
  150. netty:
  151. http:
  152. # set to false, user can custom the netty tcp server config.
  153. webServerFactoryEnabled: true
  154. selectCount: 1
  155. workerCount: 4
  156. accessLog: false
  157. serverSocketChannel:
  158. soRcvBuf: 87380
  159. soBackLog: 128
  160. soReuseAddr: false
  161. connectTimeoutMillis: 10000
  162. writeBufferHighWaterMark: 65536
  163. writeBufferLowWaterMark: 32768
  164. writeSpinCount: 16
  165. autoRead: false
  166. allocType: "pooled"
  167. messageSizeEstimator: 8
  168. singleEventExecutorPerGroup: true
  169. socketChannel:
  170. soKeepAlive: false
  171. soReuseAddr: false
  172. soLinger: -1
  173. tcpNoDelay: true
  174. soRcvBuf: 87380
  175. soSndBuf: 16384
  176. ipTos: 0
  177. allowHalfClosure: false
  178. connectTimeoutMillis: 10000
  179. writeBufferHighWaterMark: 65536
  180. writeBufferLowWaterMark: 32768
  181. writeSpinCount: 16
  182. autoRead: false
  183. allocType: "pooled"
  184. messageSizeEstimator: 8
  185. singleEventExecutorPerGroup: true
  186. instance:
  187. enabled: false
  188. registerType: zookeeper #etcd #consul
  189. serverLists: localhost:2181 #http://localhost:2379 #localhost:8848
  190. props:
  191. cross:
  192. enabled: true
  193. allowedHeaders:
  194. allowedMethods: "*"
  195. allowedAnyOrigin: true # the same of Access-Control-Allow-Origin: "*"
  196. allowedExpose: ""
  197. maxAge: "18000"
  198. allowCredentials: true
  199. switchConfig:
  200. local: true
  201. file:
  202. enabled: true
  203. maxSize : 10
  204. sync:
  205. websocket:
  206. urls: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095/websocket
  207. allowOrigin: ws://shenyu-bootstrap-svc.shenyu.svc.cluster.local:9195
  208. exclude:
  209. enabled: false
  210. paths:
  211. - /favicon.ico
  212. fallback:
  213. enabled: false
  214. paths:
  215. - /fallback/hystrix
  216. - /fallback/resilience4j
  217. health:
  218. enabled: false
  219. paths:
  220. - /actuator/health
  221. - /health_check
  222. extPlugin:
  223. path:
  224. enabled: true
  225. threads: 1
  226. scheduleTime: 300
  227. scheduleDelay: 30
  228. scheduler:
  229. enabled: false
  230. type: fixed
  231. threads: 16
  232. upstreamCheck:
  233. enabled: false
  234. timeout: 3000
  235. healthyThreshold: 1
  236. unhealthyThreshold: 1
  237. interval: 5000
  238. printEnabled: true
  239. printInterval: 60000
  240. ribbon:
  241. serverListRefreshInterval: 10000
  242. metrics:
  243. enabled: false
  244. name : prometheus
  245. host: 127.0.0.1
  246. port: 8090
  247. jmxConfig:
  248. props:
  249. jvm_enabled: true
  250. local:
  251. enabled: false
  252. sha512Key: "BA3253876AED6BC22D4A6FF53D8406C6AD864195ED144AB5C87621B6C233B548BAEAE6956DF346EC8C17F5EA10F35EE3CBC514797ED7DDD3145464E2A0BAB413"
  253. logging:
  254. level:
  255. root: info
  256. org.springframework.boot: info
  257. org.apache.ibatis: info
  258. org.apache.shenyu.bonuspoint: info
  259. org.apache.shenyu.lottery: info
  260. org.apache.shenyu: info
  • 执行 kubectl apply -f shenyu-ns.yaml

2. 部署 shenyu-admin

创建网关管理服务

  • 创建文件 shenyu-admin.yaml
  1. # 示例使用 nodeport 方式暴露端口
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. namespace: shenyu
  6. name: shenyu-admin-svc
  7. spec:
  8. selector:
  9. app: shenyu-admin
  10. type: NodePort
  11. ports:
  12. - protocol: TCP
  13. port: 9095
  14. targetPort: 9095
  15. nodePort: 31095
  16. ---
  17. # shenyu-admin
  18. apiVersion: apps/v1
  19. kind: Deployment
  20. metadata:
  21. namespace: shenyu
  22. name: shenyu-admin
  23. spec:
  24. selector:
  25. matchLabels:
  26. app: shenyu-admin
  27. replicas: 1
  28. template:
  29. metadata:
  30. labels:
  31. app: shenyu-admin
  32. spec:
  33. volumes:
  34. - name: shenyu-admin-application
  35. configMap:
  36. name: shenyu-cm
  37. items:
  38. - key: shenyu-admin-application.yml
  39. path: shenyu-admin-application.yml
  40. - name: shenyu-admin-application-h2
  41. configMap:
  42. name: shenyu-cm
  43. items:
  44. - key: shenyu-admin-application-h2.yml
  45. path: shenyu-admin-application-h2.yml
  46. containers:
  47. - name: shenyu-admin
  48. image: apache/shenyu-admin:latest
  49. imagePullPolicy: Always
  50. ports:
  51. - containerPort: 9095
  52. env:
  53. - name: 'TZ'
  54. value: 'Asia/Beijing'
  55. volumeMounts:
  56. - name: shenyu-admin-application
  57. mountPath: /opt/shenyu-admin/conf/application.yml
  58. subPath: shenyu-admin-application.yml
  59. - name: shenyu-admin-application-h2
  60. mountPath: /opt/shenyu-admin/conf/application-h2.yml
  61. subPath: shenyu-admin-application-h2.yml
  • 执行kubectl apply -f shenyu-admin.yaml

3. 部署 shenyu-bootstrap

创建网关服务

  • 创建文件 shenyu-bootstrap.yaml
  1. # 示例使用 nodeport 方式暴露端口
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. namespace: shenyu
  6. name: shenyu-bootstrap-svc
  7. spec:
  8. selector:
  9. app: shenyu-bootstrap
  10. type: NodePort
  11. ports:
  12. - protocol: TCP
  13. port: 9195
  14. targetPort: 9195
  15. nodePort: 31195
  16. ---
  17. # shenyu-bootstrap
  18. apiVersion: apps/v1
  19. kind: Deployment
  20. metadata:
  21. namespace: shenyu
  22. name: shenyu-bootstrap
  23. spec:
  24. selector:
  25. matchLabels:
  26. app: shenyu-bootstrap
  27. replicas: 1
  28. template:
  29. metadata:
  30. labels:
  31. app: shenyu-bootstrap
  32. spec:
  33. volumes:
  34. - name: shenyu-bootstrap-application
  35. configMap:
  36. name: shenyu-cm
  37. items:
  38. - key: shenyu-bootstrap-application.yml
  39. path: shenyu-bootstrap-application.yml
  40. containers:
  41. - name: shenyu-bootstrap
  42. image: apache/shenyu-bootstrap:latest
  43. ports:
  44. - containerPort: 9195
  45. env:
  46. - name: TZ
  47. value: Asia/Beijing
  48. volumeMounts:
  49. - name: shenyu-bootstrap-application
  50. mountPath: /opt/shenyu-bootstrap/conf/application.yml
  51. subPath: shenyu-bootstrap-application.yml
  • 执行 kubectl apply -f shenyu-bootstrap.yaml

示例二:使用 MySQL 作为数据库

1. 创建 Namespace和 ConfigMap

  • 创建文件 shenyu-ns.yaml
  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4. name: shenyu
  5. labels:
  6. name: shenyu
  7. ---
  8. apiVersion: v1
  9. kind: ConfigMap
  10. metadata:
  11. name: shenyu-cm
  12. namespace: shenyu
  13. data:
  14. shenyu-admin-application.yml: |
  15. server:
  16. port: 9095
  17. address: 0.0.0.0
  18. spring:
  19. profiles:
  20. active: mysql
  21. thymeleaf:
  22. cache: true
  23. encoding: utf-8
  24. enabled: true
  25. prefix: classpath:/static/
  26. suffix: .html
  27. mvc:
  28. pathmatch:
  29. matching-strategy: ant_path_matcher
  30. mybatis:
  31. config-location: classpath:/mybatis/mybatis-config.xml
  32. mapper-locations: classpath:/mappers/*.xml
  33. shenyu:
  34. register:
  35. registerType: http #http #zookeeper #etcd #nacos #consul
  36. serverLists: #localhost:2181 #http://localhost:2379 #localhost:8848
  37. props:
  38. sessionTimeout: 5000
  39. connectionTimeout: 2000
  40. checked: true
  41. zombieCheckTimes: 5
  42. scheduledTime: 10
  43. nacosNameSpace: ShenyuRegisterCenter
  44. sync:
  45. websocket:
  46. enabled: true
  47. messageMaxSize: 10240
  48. allowOrigins: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095;ws://shenyu-bootstrap-svc.shenyu.svc.cluster.local:9195;
  49. ldap:
  50. enabled: false
  51. url: ldap://xxxx:xxx
  52. bind-dn: cn=xxx,dc=xxx,dc=xxx
  53. password: xxxx
  54. base-dn: ou=xxx,dc=xxx,dc=xxx
  55. object-class: person
  56. login-field: cn
  57. jwt:
  58. expired-seconds: 86400000
  59. shiro:
  60. white-list:
  61. - /
  62. - /favicon.*
  63. - /static/**
  64. - /index**
  65. - /platform/login
  66. - /websocket
  67. - /error
  68. - /actuator/health
  69. - /swagger-ui.html
  70. - /webjars/**
  71. - /swagger-resources/**
  72. - /v2/api-docs
  73. - /csrf
  74. swagger:
  75. enable: true
  76. apidoc:
  77. gatewayUrl: http://127.0.0.1:9195
  78. envProps:
  79. - envLabel: Test environment
  80. addressLabel: Request Address
  81. addressUrl: http://127.0.0.1:9195
  82. - envLabel: Prod environment
  83. addressLabel: Request Address
  84. addressUrl: http://127.0.0.1:9195
  85. logging:
  86. level:
  87. root: info
  88. org.springframework.boot: info
  89. org.apache.ibatis: info
  90. org.apache.shenyu.bonuspoint: info
  91. org.apache.shenyu.lottery: info
  92. org.apache.shenyu: info
  93. shenyu-admin-application-mysql.yml: |
  94. shenyu:
  95. database:
  96. dialect: mysql
  97. init_script: "sql-script/mysql/schema.sql"
  98. init_enable: true
  99. spring:
  100. datasource:
  101. url: jdbc:mysql://{your_mysql_ip}:{your_mysql_port}/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false
  102. username: {your_mysql_user}
  103. password: {your_mysql_password}
  104. driver-class-name: com.mysql.jdbc.Driver
  105. shenyu-bootstrap-application.yml: |
  106. server:
  107. port: 9195
  108. address: 0.0.0.0
  109. spring:
  110. main:
  111. allow-bean-definition-overriding: true
  112. allow-circular-references: true
  113. application:
  114. name: shenyu-bootstrap
  115. codec:
  116. max-in-memory-size: 2MB
  117. cloud:
  118. discovery:
  119. enabled: false
  120. nacos:
  121. discovery:
  122. server-addr: 127.0.0.1:8848 # Spring Cloud Alibaba Dubbo use this.
  123. enabled: false
  124. namespace: ShenyuRegisterCenter
  125. eureka:
  126. client:
  127. enabled: false
  128. serviceUrl:
  129. defaultZone: http://localhost:8761/eureka/
  130. instance:
  131. prefer-ip-address: true
  132. management:
  133. health:
  134. defaults:
  135. enabled: false
  136. shenyu:
  137. matchCache:
  138. selector:
  139. selectorEnabled: false
  140. initialCapacity: 10000 # initial capacity in cache
  141. maximumSize: 10000 # max size in cache
  142. rule:
  143. initialCapacity: 10000 # initial capacity in cache
  144. maximumSize: 10000 # max size in cache
  145. trie:
  146. childrenSize: 10000
  147. pathVariableSize: 1000
  148. pathRuleCacheSize: 1000
  149. matchMode: antPathMatch
  150. netty:
  151. http:
  152. # set to false, user can custom the netty tcp server config.
  153. webServerFactoryEnabled: true
  154. selectCount: 1
  155. workerCount: 4
  156. accessLog: false
  157. serverSocketChannel:
  158. soRcvBuf: 87380
  159. soBackLog: 128
  160. soReuseAddr: false
  161. connectTimeoutMillis: 10000
  162. writeBufferHighWaterMark: 65536
  163. writeBufferLowWaterMark: 32768
  164. writeSpinCount: 16
  165. autoRead: false
  166. allocType: "pooled"
  167. messageSizeEstimator: 8
  168. singleEventExecutorPerGroup: true
  169. socketChannel:
  170. soKeepAlive: false
  171. soReuseAddr: false
  172. soLinger: -1
  173. tcpNoDelay: true
  174. soRcvBuf: 87380
  175. soSndBuf: 16384
  176. ipTos: 0
  177. allowHalfClosure: false
  178. connectTimeoutMillis: 10000
  179. writeBufferHighWaterMark: 65536
  180. writeBufferLowWaterMark: 32768
  181. writeSpinCount: 16
  182. autoRead: false
  183. allocType: "pooled"
  184. messageSizeEstimator: 8
  185. singleEventExecutorPerGroup: true
  186. instance:
  187. enabled: false
  188. registerType: zookeeper #etcd #consul
  189. serverLists: localhost:2181 #http://localhost:2379 #localhost:8848
  190. props:
  191. cross:
  192. enabled: true
  193. allowedHeaders:
  194. allowedMethods: "*"
  195. allowedAnyOrigin: true # the same of Access-Control-Allow-Origin: "*"
  196. allowedExpose: ""
  197. maxAge: "18000"
  198. allowCredentials: true
  199. switchConfig:
  200. local: true
  201. file:
  202. enabled: true
  203. maxSize : 10
  204. sync:
  205. websocket:
  206. urls: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095/websocket
  207. allowOrigin: ws://shenyu-bootstrap-svc.shenyu.svc.cluster.local:9195
  208. exclude:
  209. enabled: false
  210. paths:
  211. - /favicon.ico
  212. fallback:
  213. enabled: false
  214. paths:
  215. - /fallback/hystrix
  216. - /fallback/resilience4j
  217. health:
  218. enabled: false
  219. paths:
  220. - /actuator/health
  221. - /health_check
  222. extPlugin:
  223. path:
  224. enabled: true
  225. threads: 1
  226. scheduleTime: 300
  227. scheduleDelay: 30
  228. scheduler:
  229. enabled: false
  230. type: fixed
  231. threads: 16
  232. upstreamCheck:
  233. enabled: false
  234. timeout: 3000
  235. healthyThreshold: 1
  236. unhealthyThreshold: 1
  237. interval: 5000
  238. printEnabled: true
  239. printInterval: 60000
  240. ribbon:
  241. serverListRefreshInterval: 10000
  242. metrics:
  243. enabled: false
  244. name : prometheus
  245. host: 127.0.0.1
  246. port: 8090
  247. jmxConfig:
  248. props:
  249. jvm_enabled: true
  250. local:
  251. enabled: false
  252. sha512Key: "BA3253876AED6BC22D4A6FF53D8406C6AD864195ED144AB5C87621B6C233B548BAEAE6956DF346EC8C17F5EA10F35EE3CBC514797ED7DDD3145464E2A0BAB413"
  253. logging:
  254. level:
  255. root: info
  256. org.springframework.boot: info
  257. org.apache.ibatis: info
  258. org.apache.shenyu.bonuspoint: info
  259. org.apache.shenyu.lottery: info
  260. org.apache.shenyu: info
  • 执行 kubectl apply -f shenyu-ns.yaml

2. 部署 shenyu-admin

  • 创建文件 shenyu-admin.yaml
  1. # 示例使用 nodeport 方式暴露端口
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. namespace: shenyu
  6. name: shenyu-admin-svc
  7. spec:
  8. selector:
  9. app: shenyu-admin
  10. type: NodePort
  11. ports:
  12. - protocol: TCP
  13. port: 9095
  14. targetPort: 9095
  15. nodePort: 31095
  16. ---
  17. # shenyu-admin
  18. apiVersion: apps/v1
  19. kind: Deployment
  20. metadata:
  21. namespace: shenyu
  22. name: shenyu-admin
  23. spec:
  24. selector:
  25. matchLabels:
  26. app: shenyu-admin
  27. replicas: 1
  28. template:
  29. metadata:
  30. labels:
  31. app: shenyu-admin
  32. spec:
  33. volumes:
  34. - name: shenyu-admin-application
  35. configMap:
  36. name: shenyu-cm
  37. items:
  38. - key: shenyu-admin-application.yml
  39. path: shenyu-admin-application.yml
  40. - name: shenyu-admin-application-mysql
  41. configMap:
  42. name: shenyu-cm
  43. items:
  44. - key: shenyu-admin-application-mysql.yml
  45. path: shenyu-admin-application-mysql.yml
  46. - name: mysql-connector-volume
  47. emptyDir: {}
  48. initContainers:
  49. - name: download-mysql-jar
  50. image: busybox:1.35.0
  51. command: [ "sh","-c"]
  52. args: ["wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.23/mysql-connector-java-8.0.23.jar;
  53. wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.23/mysql-connector-java-8.0.23.jar.md5;
  54. if [ $(md5sum mysql-connector-java-8.0.23.jar | cut -d ' ' -f1) = $(cat mysql-connector-java-8.0.23.jar.md5) ];
  55. then echo success;
  56. else echo failed;
  57. exit 1;
  58. fi;
  59. mv /mysql-connector-java-8.0.23.jar /opt/shenyu-admin/ext-lib/mysql-connector-java.jar" ]
  60. volumeMounts:
  61. - name: mysql-connector-volume
  62. mountPath: /opt/shenyu-admin/ext-lib
  63. containers:
  64. - name: shenyu-admin
  65. image: apache/shenyu-admin:latest
  66. imagePullPolicy: Always
  67. ports:
  68. - containerPort: 9095
  69. env:
  70. - name: 'TZ'
  71. value: 'Asia/Beijing'
  72. - name: SPRING_PROFILES_ACTIVE
  73. value: mysql
  74. volumeMounts:
  75. - name: shenyu-admin-application
  76. mountPath: /opt/shenyu-admin/conf/application.yml
  77. subPath: shenyu-admin-application.yml
  78. - name: shenyu-admin-application-mysql
  79. mountPath: /opt/shenyu-admin/conf/application-mysql.yml
  80. subPath: shenyu-admin-application-mysql.yml
  81. - name: mysql-connector-volume
  82. mountPath: /opt/shenyu-admin/ext-lib
  • 执行kubectl apply -f shenyu-admin.yaml

3. 部署 shenyu-bootstrap

  • 创建文件 shenyu-bootstrap.yaml
  1. # 示例使用 nodeport 方式暴露端口
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. namespace: shenyu
  6. name: shenyu-bootstrap-svc
  7. spec:
  8. selector:
  9. app: shenyu-bootstrap
  10. type: NodePort
  11. ports:
  12. - protocol: TCP
  13. port: 9195
  14. targetPort: 9195
  15. nodePort: 31195
  16. ---
  17. # shenyu-bootstrap
  18. apiVersion: apps/v1
  19. kind: Deployment
  20. metadata:
  21. namespace: shenyu
  22. name: shenyu-bootstrap
  23. spec:
  24. selector:
  25. matchLabels:
  26. app: shenyu-bootstrap
  27. replicas: 1
  28. template:
  29. metadata:
  30. labels:
  31. app: shenyu-bootstrap
  32. spec:
  33. volumes:
  34. - name: shenyu-bootstrap-application
  35. configMap:
  36. name: shenyu-cm
  37. items:
  38. - key: shenyu-bootstrap-application.yml
  39. path: shenyu-bootstrap-application.yml
  40. containers:
  41. - name: shenyu-bootstrap
  42. image: apache/shenyu-bootstrap:latest
  43. ports:
  44. - containerPort: 9195
  45. env:
  46. - name: TZ
  47. value: Asia/Beijing
  48. volumeMounts:
  49. - name: shenyu-bootstrap-application
  50. mountPath: /opt/shenyu-bootstrap/conf/application.yml
  51. subPath: shenyu-bootstrap-application.yml
  • 执行 kubectl apply -f shenyu-bootstrap.yaml

测试访问

访问地址http://{K8S\_CLUSTER\_IP}:31095/

账号密码:admin/123456