Kubernetes Pod参数未在Args下的Service中显示:无错误 [英] Kubernetes pod arguments are not displayed in Service under Args: without error

查看:191
本文介绍了Kubernetes Pod参数未在Args下的Service中显示:无错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个singlePod.yaml文件来正确描述传递参数的kubernetes pod服务,并且可以像这样运行: kubectl创建-f ./singlePod.yaml

I created a singlePod.yaml file to properly describe the kubernetes pod service that passes arguments, and can run like this: kubectl create -f ./singlePod.yaml

我希望调用的参数匹配Docker:

I want the arguments called to match Docker:

docker run -it -p 8080:8080 joethecoder2/spring-boot-web cassandra_ip=127.0.0.1 cassandra_port=9042

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
    env:
    - name: "cassandra_ip"
      value: "127.0.0.1"
    - name: "cassandra_port"
      value: "9042"
    command: ["java","-jar", "spring-boot-web-0.0.1-SNAPSHOT.jar", "cassandra_ip=127.0.0.1", "cassandra_port=9042"]
    args: ["$(cassandra_ip)", "$(cassandra_port)"]
  restartPolicy: OnFailure
<!-- Paste the part of the code that shows the problem. (Please indent 4 spaces.) -->

问题在于,尽管参数已添加到以下服务中,但这些参数不会对调用程序(spring-boot-web-0.0.1-SNAPSHOT.jar)生效

The problem is that although the arguments have been added to the below service, the arguments do not take effect to the calling program (spring-boot-web-0.0.1-SNAPSHOT.jar)

Name:       spring-boot-web-demo
Namespace:  default
Node:       minikube/192.168.64.3
Start Time: Thu, 07 Dec 2017 12:08:10 -0500
Labels:     purpose=demonstrate-spring-boot-web
Annotations:    <none>
Status:     Running
IP:     172.17.0.2
Controllers:    <none>
Containers:
  spring-boot-web:
    Container ID:   docker://1c9543e412b50b36182528d690121014dfe7c9dd6409ce689d1a08fbad7c2436
    Image:      docker.io/joethecoder2/spring-boot-web
    Image ID:       docker-pullable://joethecoder2/spring-boot-web@sha256:ebf94365075e0ee16a50cab41d8e1307785a93c60be600f94bb82a4dbefb6bc0
    Port:       
    Command:
      java
      -jar
      spring-boot-web-0.0.1-SNAPSHOT.jar
      cassandra_ip=127.0.0.1
      cassandra_port=9042
    Args:
      $(cassandra_ip)
      $(cassandra_port)
    State:      Running
      Started:      Thu, 07 Dec 2017 12:08:11 -0500
    Ready:      True
    Restart Count:  0
    Environment:
      cassandra_ip: 127.0.0.1
      cassandra_port:   9042
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-wgdn6 (ro)
Conditions:
  Type      Status
  Initialized   True 
  Ready     True 
  PodScheduled  True 
Volumes:
  default-token-wgdn6:
    Type:   Secret (a volume populated by a Secret)
    SecretName: default-token-wgdn6
    Optional:   false
QoS Class:  BestEffort
Node-Selectors: <none>
Tolerations:    <none>
Events:
  FirstSeen LastSeen    Count   From            SubObjectPath               Type        Reason          Message
  --------- --------    -----   ----            -------------               --------    ------          -------
  8m        8m      1   default-scheduler                       Normal      Scheduled       Successfully assigned spring-boot-web-demo to minikube
  8m        8m      1   kubelet, minikube                       Normal      SuccessfulMountVolume   MountVolume.SetUp succeeded for volume "default-token-wgdn6" 
  8m        8m      1   kubelet, minikube   spec.containers{spring-boot-web}    Normal      Pulling         pulling image "docker.io/joethecoder2/spring-boot-web"
  8m        8m      1   kubelet, minikube   spec.containers{spring-boot-web}    Normal      Pulled          Successfully pulled image "docker.io/joethecoder2/spring-boot-web"
  8m        8m      1   kubelet, minikube   spec.containers{spring-boot-web}    Normal      Created         Created container
  8m        8m      1   kubelet, minikube   spec.containers{spring-boot-web}    Normal      Started         Started container

我期望调用Java程序的结果: 使用cassandra_ip和cassandra_port

I am expecting the results from the calling java program: to use the cassandra_ip and cassandra_port

该服务未正确显示该服务正在显示的参数,并且docker内部正在运行的Java程序也未显示该参数已被调用.

The service, does not properly show the arguments being displayed by the service, and also the running java program inside docker, does not show that the arguments are called.

Command:
      java
      -jar
      spring-boot-web-0.0.1-SNAPSHOT.jar
      cassandra_ip=127.0.0.1
      cassandra_port=9042
    Args:
      $(cassandra_ip)
      $(cassandra_port)

推荐答案

像这样更改它.它会起作用.

change it like this. it will work.

spec:
  containers:
  - name: spring-boot-web
    image: docker.io/joethecoder2/spring-boot-web
    env:
    - name: "cassandra_ip"
      value: "127.0.0.1"
    - name: "cassandra_port"
      value: "9042"
    command: ["/bin/sh","-c", "java -jar spring-boot-web-0.0.1-SNAPSHOT.jar cassandra_ip=$cassandra_ip", "cassandra_port=$cassandra_port]
  restartPolicy: OnFailure

这篇关于Kubernetes Pod参数未在Args下的Service中显示:无错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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