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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Deploy to Kubernetes using Kustomize

Edited

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

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
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

140 views 1 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you