k8s部署

    1. h2 过程类似,需要注意的两个地方
    2. 1. 需要加载 mysql-connector.jar,所以需要一个文件存储的地方
    3. 2. 需要指定外部 mysql 数据库配置,通过 endpoint 来代理外部 mysql 数据库
    4. 具体流程如下:
    5. 1. 创建 nameSpace configMap
    6. 2. 创建 endpoint 代理外部 mysql
    7. 3. 创建 pv 存储 mysql-connector.jar
    8. 4. 部署 shenyu-admin
    9. 5. 部署 shenyu-bootstrap
    • 创建文件 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. application-local.yml: |
    15. server:
    16. port: 9195
    17. address: 0.0.0.0
    18. spring:
    19. main:
    20. allow-bean-definition-overriding: true
    21. application:
    22. name: shenyu-bootstrap
    23. management:
    24. health:
    25. defaults:
    26. enabled: false
    27. shenyu:
    28. local:
    29. enabled: true
    30. file:
    31. enabled: true
    32. cross:
    33. enabled: true
    34. dubbo:
    35. parameter: multi
    36. sync:
    37. websocket:
    38. urls: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095/websocket
    39. exclude:
    40. enabled: false
    41. paths:
    42. - /favicon.ico
    43. extPlugin:
    44. enabled: true
    45. threads: 1
    46. scheduleTime: 300
    47. scheduleDelay: 30
    48. scheduler:
    49. enabled: false
    50. type: fixed
    51. threads: 16
    52. logging:
    53. level:
    54. root: info
    55. org.springframework.boot: info
    56. org.apache.ibatis: info
    57. org.apache.shenyu.bonuspoint: info
    58. org.apache.shenyu.lottery: info
    59. org.apache.shenyu: info
    • 执行 kubectl apply -f shenyu-ns.yaml

    2. 部署 shenyu-admin

    • 创建文件 shenyu-admin.yaml
    • 执行kubectl apply -f shenyu-admin.yaml
    • 创建文件 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. apiVersion: apps/v1
    18. kind: Deployment
    19. metadata:
    20. namespace: shenyu
    21. spec:
    22. selector:
    23. matchLabels:
    24. app: shenyu-bootstrap
    25. replicas: 1
    26. template:
    27. metadata:
    28. labels:
    29. app: shenyu-bootstrap
    30. spec:
    31. volumes:
    32. - name: shenyu-bootstrap-config
    33. configMap:
    34. name: shenyu-cm
    35. items:
    36. - key: application-local.yml
    37. path: application-local.yml
    38. containers:
    39. - name: shenyu-bootstrap
    40. image: apache/shenyu-bootstrap:${current.version}
    41. ports:
    42. - containerPort: 9195
    43. env:
    44. - name: TZ
    45. value: Asia/Beijing
    46. volumeMounts:
    47. - name: shenyu-bootstrap-config
    48. mountPath: /opt/shenyu-bootstrap/conf/application-local.yml
    49. subPath: application-local.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. application-local.yml: |
    15. server:
    16. port: 9195
    17. address: 0.0.0.0
    18. spring:
    19. main:
    20. allow-bean-definition-overriding: true
    21. application:
    22. name: shenyu-bootstrap
    23. management:
    24. health:
    25. defaults:
    26. enabled: false
    27. shenyu:
    28. local:
    29. enabled: true
    30. file:
    31. enabled: true
    32. cross:
    33. enabled: true
    34. dubbo:
    35. parameter: multi
    36. sync:
    37. websocket:
    38. urls: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095/websocket
    39. exclude:
    40. enabled: false
    41. paths:
    42. - /favicon.ico
    43. extPlugin:
    44. enabled: true
    45. threads: 1
    46. scheduleTime: 300
    47. scheduleDelay: 30
    48. scheduler:
    49. enabled: false
    50. type: fixed
    51. threads: 16
    52. logging:
    53. level:
    54. root: info
    55. org.springframework.boot: info
    56. org.apache.ibatis: info
    57. org.apache.shenyu.bonuspoint: info
    58. org.apache.shenyu.lottery: info
    59. org.apache.shenyu: info
    60. application-mysql.yml: |
    61. spring.datasource.url: jdbc:mysql://mysql.shenyu.svc.cluster.local:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false
    62. spring.datasource.username: {your_mysql_user}
    63. spring.datasource.password: {your_mysql_password}
    • 执行 kubectl apply -f shenyu-ns.yaml
    • 创建文件 shenyu-ep.yaml
    • 执行 kubectl apply -f shenyu-ep.yaml

    3. 创建 pv 存储 mysql-connector.jar

    • 创建文件 shenyu-store.yaml
    1. # 示例使用 pvc、pv、storageClass 来存储文件
    2. apiVersion: v1
    3. metadata:
    4. spec:
    5. capacity:
    6. storage: 1Gi
    7. volumeMode: Filesystem
    8. accessModes:
    9. - ReadWriteOnce
    10. persistentVolumeReclaimPolicy: Delete
    11. storageClassName: local-storage
    12. local:
    13. path: /home/shenyu/shenyu-admin/k8s-pv # 指定节点上的目录,该目录下面需要包含 mysql-connector.jar
    14. nodeAffinity:
    15. required:
    16. nodeSelectorTerms:
    17. - matchExpressions:
    18. - key: kubernetes.io/hostname
    19. operator: In
    20. values:
    21. - {your_node_name} # 指定节点
    22. ---
    23. kind: PersistentVolumeClaim
    24. apiVersion: v1
    25. metadata:
    26. name: shenyu-pvc
    27. namespace: shenyu
    28. spec:
    29. accessModes:
    30. - ReadWriteOnce
    31. resources:
    32. requests:
    33. storage: 1Gi
    34. storageClassName: local-storage
    35. ---
    36. apiVersion: storage.k8s.io/v1
    37. kind: StorageClass
    38. metadata:
    39. name: local-storage
    40. provisioner: kubernetes.io/no-provisioner
    41. volumeBindingMode: WaitForFirstConsumer
    • 执行 kubectl apply -f shenyu-store.yaml
    • pv挂载目录下上传 mysql-connector.jar
    • 创建文件 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: mysql-connector-volume
    35. persistentVolumeClaim:
    36. claimName: shenyu-pvc
    37. - name: shenyu-admin-config
    38. configMap:
    39. name: shenyu-cm
    40. items:
    41. - key: application-mysql.yml
    42. path: application-mysql.yml
    43. containers:
    44. - name: shenyu-admin
    45. image: apache/shenyu-admin:${current.version}
    46. imagePullPolicy: Always
    47. ports:
    48. - containerPort: 9095
    49. env:
    50. - name: 'TZ'
    51. value: 'Asia/Beijing'
    52. - name: SPRING_PROFILES_ACTIVE
    53. value: mysql
    54. volumeMounts:
    55. - name: shenyu-admin-config
    56. mountPath: /opt/shenyu-admin/config/application-mysql.yml
    57. subPath: application-mysql.yml
    58. - mountPath: /opt/shenyu-admin/ext-lib
    59. name: mysql-connector-volume
    • 执行

    3. 部署 shenyu-bootstrap

    • 创建文件 shenyu-bootstrap.yaml
    • 执行 kubectl apply -f shenyu-bootstrap.yaml