reference variables from pom.xml to deployment.yaml

7/24/2019

i want to use maven pom.xml variables in a kubernetes deployment.yaml file. the variables i want to reference are ${project.artifactId} and ${project.version} which is pulled from

pom.xml

<groupId>my-project</groupId>
<artifactId>>my-project</artifactId>
<version>1.0.0-SNAPSHOT</version>

and this is what i want to achieve

deploment.yaml


apiVersion: v1
kind: Pod
spec:
  containers:
    - name: my-project
      image: ${project.artifactId}:${project.version}

with this attempt i get an InvalidImageName error. enter image description here

please advice on which better way of doing this.

-- muzi jack
java
kubernetes
pom.xml

1 Answer

7/25/2019

I would say its issue with your deploment.yaml content. I have use it (with nginx image) on K8s and get error below:

error: error when retrieving current configuration of:
Resource: "/v1, Resource=pods", GroupVersionKind: "/v1, Kind=Pod"
Name: "", Namespace: "default"
Object: &{map["apiVersion":"v1" "kind":"Pod" "spec":map["containers":[map["name":"test" "image":"nginx"]]] "metadata":map["namespace":"default" "annotations":map["kubectl.kubernetes.io/last-applied-configuration":""]]]}
from server for: "pod.yaml": resource name may not be empty

In your current file you have named only container. You have to specify your POD name using metadata.name. In metadata section you can also specify namespace.

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx
    image: nginx

In addition keep in mind that kind: Pod and kind: Deployment are two different things (bit confused regarding your YAML file name).

-- PjoterS
Source: StackOverflow