Kubernetes POD arguments are not passing to service, however Docker arguments are passing correctly

前端 未结 1 1663
借酒劲吻你
借酒劲吻你 2021-01-17 03:29

Problem Statement:

I have a created a Docker image successfully from docker.io/joethecoder2/spring-boot-web. It has been tested with command line argum

相关标签:
1条回答
  • 2021-01-17 04:23

    If you want to inject environment variable into the container.It's better to use ConfigMap so it provides flexibility as well as separation of concern.

    apiVersion: v1
    kind: Pod
    metadata:
      name: spring-boot-web-demo
      labels:
        purpose: demonstrate-spring-boot-web
    spec:
      containers:
      - name: spring-boot-web
        image: docker.io/joethecoder2/spring-boot-web
        command: ["java","-jar", "spring-boot-web-0.0.1-SNAPSHOT.jar"]
      env:
      - name: DCASSANDRA_IP
        valueFrom:
            configMapKeyRef:
                key: Dcassandra_ip
                name: env-values
      - name: DCASSANDRA_PORT
        valueFrom:
            configMapKeyRef:
                key: Dcassandra_port
                name: env-values
      restartPolicy: OnFailure
    
    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: env-values
    data:
      Dcassandra_port=9042
      Dcassandra_ip=127.0.0.1
    

    Now You need to write a Service Manifest file to expose this container in order to access it. I have attached links for further research.

    ConfigMap

    Service

    0 讨论(0)
提交回复
热议问题