【K8S】helm chart多环境部署最佳实践-示例

Chart.yaml

apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: nginx
version: 0.1.0

values.yaml

# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 2

image:
  repository: nginx
  tag: 1.15-alpine

envs:
  PARAM_JVMTOOL: "123456"
  PARAM_SPRING: "654321"

resources:
  requests:
    cpu: "0.1"
    memory: "256M"

values-dev.yaml

# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

envs:
  PARAM_AAA: "123456_aaa_dev"
  PARAM_BBB: "123456_bbb_dev"
  PARAM_CCC: "123456_ccc_dev"
  PARAM_DDD: "123456_ddd_dev"

resources:
  limits:
    cpu: "0.5"
    memory: "512M"

values-test.yaml

# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

envs:
  PARAM_AAA: "123456_aaa_test"
  PARAM_BBB: "123456_bbb_test"
  PARAM_CCC: "123456_ccc_test"
  PARAM_DDD: "123456_ddd_test"

resources:
  limits:
    cpu: "0.5"
    memory: "512M"

values-stage.yaml

# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

envs:
  PARAM_AAA: "123456_aaa_stage"
  PARAM_BBB: "123456_bbb_stage"
  PARAM_CCC: "123456_ccc_stage"
  PARAM_DDD: "123456_ddd_stage"

resources:
  limits:
    cpu: "0.5"
    memory: "1024M"

values-prod.yaml

# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

envs:
  PARAM_AAA: "123456_aaa_prod"
  PARAM_BBB: "123456_bbb_prod"
  PARAM_CCC: "123456_ccc_prod"
  PARAM_DDD: "123456_ddd_prod"

resources:
  limits:
    cpu: "0.5"
    memory: "1024M"

templates/deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: Always
        name: nginx
        command: ["/bin/sh", "-c", "echo $HOSTNAME > /usr/share/nginx/html/index.html && exec nginx -g 'daemon off;'"]
        ports: 
        - containerPort: 80
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
        env:
        {{- range $key, $value := .Values.envs }}
        - name: {{ $key }}
          value: {{ $value | quote }}
        {{- end }}

templates/service.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: nginx
  sessionAffinity: None
  type: ClusterIP
  clusterIP: None

---
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-nodeport
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
    # 30000-32767
    # nodePort: 30080
  selector:
    app: hello-world
  #sessionAffinity: None
  type: NodePort

deploy.sh

#!/bin/bash

envType=${1:-dev}
helm install --name=nginx -f values.yaml -f values-dev.yaml --set image.repository=docker-repo.xxx.com/k2/nginx --set image.tag=1.12.2 --set envs.PARAM_JVMTOOL=xxxxxxxx --set envs.PARAM_AAA=yyyyyyyyy --dry-run --debug .

debug.txt

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: docker-repo.xxx.com/k2/nginx:1.12.2
        imagePullPolicy: Always
        name: nginx
        command: ["/bin/sh", "-c", "echo $HOSTNAME > /usr/share/nginx/html/index.html && exec nginx -g 'daemon off;'"]
        ports: 
        - containerPort: 80
        resources:
          limits:
            cpu: "0.5"
            memory: 512M
          requests:
            cpu: "0.1"
            memory: 256M
          
        env:
        - name: PARAM_AAA
          value: "yyyyyyyyy"
        - name: PARAM_BBB
          value: "123456_bbb_dev"
        - name: PARAM_CCC
          value: "123456_ccc_dev"
        - name: PARAM_DDD
          value: "123456_ddd_dev"
        - name: PARAM_JVMTOOL
          value: "xxxxxxxx"
        - name: PARAM_SPRING
          value: "654321"

 

转载于:https://www.cnblogs.com/junneyang/p/11302143.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值