创建秘钥

# mysql secret
apiVersion: v1
kind: Secret
metadata:
  name: mysql-secret
type: Opaque
data:
  username: cG9z
  password: RE1rSXpBMitPSWs9

 # redis secret
apiVersion: v1
kind: Secret
metadata:
  name: redis-secret
type: Opaque
data:
  password: K0tqN09VZytoTEpsN1dzT2MyV1FnUT09

# mq secret
apiVersion: v1
kind: Secret
metadata:
  name: mq-secret
type: Opaque
data:
  username: cG9zX3VzZXI=
  password: RDVyWElTL29zdVk9

配置configmap

kind: ConfigMap
apiVersion: v1
metadata:
  name: common-config
data:
  MYSQL_HOST: 172.24.201.91
  MYSQL_PORT: '3306'
  RADIS_HOST: 172.24.201.91
  RADIS_PORT: '6379'
  REDIS_HOST: 172.24.201.91
  REDIS_PORT: '6379'
  RABBITMQ_HOST: 172.24.201.91
  RABBITMQ_PORT: '5672'
  LOGSTASH_HOST: 172.24.201.88
  LOGSTASH_PORT: '4567'

通过evn使用secret

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: spring-boot-docker-image-test-deployment
spec:
  replicas: 1 
  template: 
    metadata:
      labels:
        app: spring-boot-docker-image-test
    spec:
      containers:
      - name: spring-boot-docker-image-test
        image: harbor.sunhaojie.com/library/spring_boot_docker_image_test:v001.013
        imagePullPolicy: Always
        env:
          - name: LOGSTASH_HOST
            valueFrom:
              configMapKeyRef:
                name: common-config
                key: LOGSTASH_HOST
          - name: LOGSTASH_PORT
            valueFrom:
              configMapKeyRef:
                name: common-config
                key: LOGSTASH_PORT
          - name: MYSQL_HOST
            valueFrom:
              configMapKeyRef:
                name: common-config
                key: MYSQL_HOST
          - name: MYSQL_PORT
            valueFrom:
              configMapKeyRef:
                name: common-config
                key: MYSQL_PORT
          - name: MYSQL_USERNAME
            valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: username
          - name: MYSQL_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: password
      imagePullSecrets:
      - name: harbor.sunhaojie.com


kind: Service
apiVersion: v1
metadata:
  namespace: test
  name: spring-boot-docker-image-test-service
spec:
  selector:
    app: spring-boot-docker-image-test
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080