使用 helm 构建后端使用的 chart (三)

使用模板部署后端服务

在服务器上添加 helm repo

helm repo add devharbor https://devharbor.junengcloud.com/chartrepo/helm

helm repo ls

创建服务

mkdir -p /data/yaml/test/reform-gateway/

kubectl create ns test

cd /data/yaml/test/reform-gateway/

mkdir charts templates

# 创建 Chart.yaml
vi Chart.yaml
apiVersion: v2
name: reform-gateway
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

dependencies:
  - name: hdyl-jdk11
    version: 0.1.1
    repository: https://devharbor.junengcloud.com/chartrepo/helm

# 创建 values.yaml
vi values.yaml
hdyl-jdk11:
  # app 名字
  appName: reform-gateway

  # 副本数
  replicaCount: 1

  # 镜像信息
  image:
    repository: harbor.abc.com/test/reform-gateway
    tag: "1"
    pullPolicy: IfNotPresent

  # 资源限制
  resources:
    limits:
      cpu: 1
      memory: 2Gi
    requests:
      cpu: 50m
      memory: 256Mi

  # 环境变量
  env:
    - name: server.port      # 后端在K8S部署的服务端口都为8080
      value: "8080"
    - name: PROFILES_ACTIVE
      value: "test"
    - name: spring.cloud.nacos.config.server-addr
      value: "http://192.168.1.81:8848"
    - name: spring.cloud.nacos.config.namespace
      value: "xxxxxx-xxxx-xxxx-xxxx-xxxxxx"

  service:
    create: false
    type: NodePort
    nodePort: 30002

  # 镜像拉取秘钥
  imagePullSecrets:
    - name: harbor

  ingress:
    enabled: false
    annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/proxy-body-size: "300m"
      nginx.ingress.kubernetes.io/proxy-send-timeout: "300"
      nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
      nginx.ingress.kubernetes.io/proxy-connect-timeout: "300"
    hosts:
      rules:
      - host: www.abc.com

  # 节点选择
  nodeSelector: {}
  #nodeSelector:
  #  nodeName: k8s-node2

  tolerations: []

  affinity: {}

  podAnnotations: {}

  podSecurityContext: {}

启动

cd /data/yaml/test
helm dependency update reform-gateway/
helm -n test install reform-gateway ./reform-gateway

# 查看
helm -n test ls
posted @ 2024-11-29 11:36  klvchen  阅读(31)  评论(0)    收藏  举报