Kubernetes POD参数未传递给服务,但是Docker参数正确传递 [英] Kubernetes POD arguments are not passing to service, however Docker arguments are passing correctly

查看:442
本文介绍了Kubernetes POD参数未传递给服务,但是Docker参数正确传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述:

我已经从docker.io/joethecoder2/spring-boot-web成功创建了一个Docker映像.它已经通过命令行参数进行了测试,并且可以在Docker本地正常运行.

I have a created a Docker image successfully from docker.io/joethecoder2/spring-boot-web. It has been tested with command line arguments, and those work correctly locally with Docker.

我正在尝试将传递给Docker的java参数传递给使用单个图像docker.io/joethecoder2/spring-boot-web

I am trying to pass java arguments that are passed to Docker to a Kubernetes POD that is defined with a single image docker.io/joethecoder2/spring-boot-web

传递参数的目的是让POD知道数据库服务的IP地址和端口号.

The purpose of passing the arguments is to let the POD know what the IP address and port number are for the database service.

问题定义:

我在这里定义了Kubernetes POD,但是我认为参数没有从 singlePod.yaml .

I have defined a Kubernetes POD here, however I believe the arguments are not passed correctly from singlePod.yaml when the POD is running the service.

预期结果:

我希望Kubernetes POD与定义的Docker映像兼容

I expect that the Kubernetes POD be compatible with the Docker image defined here.

我希望Kubernetes POD像Docker一样接受参数

I expect that the Kubernetes POD accept arguments just like Docker does here:

docker run -it -p 8080:8080 joethecoder2/spring-boot-web -Dcassandra_ip = 127.0.0.1 -Dcassandra_port = 9042

docker run -it -p 8080:8080 joethecoder2/spring-boot-web -Dcassandra_ip=127.0.0.1 -Dcassandra_port=9042

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' 'http://localhost:8080/restaurant/arguments'

返回正确的结果-> 127.0.0.1:9042

Correct result is returned-> 127.0.0.1:9042

结果错误:

我知道实际参数没有传递到POD,因为当我运行以下服务时,我没有收到返回的参数.

I know that the actual arguments are not passed to the POD, because when I run the following service, I receive no arguments returned.

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' 'http://192.168.64.3:32308/restaurant/arguments'

返回错误结果->:

预期结果-> 127.0.0.1:9042(在singlePod.yaml文件中定义)

Expected result -> 127.0.0.1:9042, as defined in the singlePod.yaml file

即使POD定义文件知道参数是静态定义的,为什么也缺少参数?

Why are the arguments missing, even though the POD definition file knows that the arguments have been defined staticly?

推荐答案

如果要将环境变量注入到容器中,最好使用ConfigMap,这样可以提供灵活性以及关注点分离.

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

现在,您需要编写一个Service Manifest文件来公开此容器,以便对其进行访问. 我已附上链接以供进一步研究.

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

服务

这篇关于Kubernetes POD参数未传递给服务,但是Docker参数正确传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆