在Args下的服务中不显示Kubernetes pod参数:没有错误

时间:2017-12-07 17:23:05

标签: kubernetes

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

我希望调用的参数匹配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)

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

该服务没有正确显示服务显示的参数,以及docker中运行的java程序,也没有显示参数被调用。

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)

1 个答案:

答案 0 :(得分:0)

像这样改变它。它会起作用。

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