Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Deploy to Kubernetes using Kustomize

Magnus Hauge Bakke
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 4, 2020

I am trying to deploy changes to my cluster using `kubectl apply -k ./` in a pipeline. My pipeline looks like this:

pipelines:
custom:
update-ref:
- step:
script:
- sed -E -i "s|([^-]- image:[^:]+).*|\1:$APP_COMMIT|g" deployments/app.yaml
- git add deployments/app.yaml
- git commit -m "[skip ci] Updating deployments/app.yaml with latest build number."
- git push
- pipe: atlassian/kubectl-run:1.1.6
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
KUBECTL_ARGS:
- '-k'
RESOURCE_PATH: './'
# WITH_DEFAULT_LABELS: 'false'

 But I get the following error:

Status: Downloaded newer image for bitbucketpipelines/kubectl-run:1.1.6Traceback (most recent call last):  File "/pipe.py", line 121, in <module>    pipe.run()  File "/pipe.py", line 112, in run    self.handle_apply()  File "/pipe.py", line 77, in handle_apply    self.update_labels_in_metadata(template_file, labels)  File "/pipe.py", line 31, in update_labels_in_metadata    yaml_doc['metadata'].setdefault('labels', {}).update(labels)KeyError: 'metadata'

I have also tried turning off default labels.

1 answer

3 votes
Magnus Hauge Bakke
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 4, 2020

After reviewing the code for kubectl-run I found that if the command is "apply" the -f parameter will be forced and it will only parse yaml-files (not directories).

Since I supplied a directory it would try to parse all the yaml-files inside, looking for metadata in each. kustomization.yaml does not have any metadata and this would lead to the error.

But if I added my whole command it would be parsed as any other command.

I updated my pipeline to the following:

pipelines:
custom:
update-ref:
- step:
script:
- sed -E -i "s|([^-]- image:[^:]+).*|\1:$APP_COMMIT|g" deployments/app.yaml
- git add deployments/app.yaml
- git commit -m "[skip ci] Updating deployments/app.yaml with latest build number."
- git push
- pipe: atlassian/kubectl-run:1.1.6
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply -k ./'

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events