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

微笑、不失礼 提交于 2019-12-02 07:49:16

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!