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

replace the image value in kubernetes yaml.

Hi,

I have created  a  bitbucket pipeline like below and now able to push image to container registry with build number as tag.

But failing to pull the same image in kubernetes deployment yml.

pipeline.yml

steps:
- step: &Build
name: Build and publish docker image.
services:
- docker # Enable Docker for your repository
image: maven:3.6.1-jdk-8
script:
- mvn -DskipTests -B package # -B batch mode makes Maven less verbose
- export IMAGE_NAME=$REGISTRY_NON_PROD/$SERVICE_NAME:${BITBUCKET_BUILD_NUMBER}
- docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_PASSWORD $REGISTRY_NON_PROD
- docker build -t $REGISTRY_NON_PROD/$SERVICE_NAME:${BITBUCKET_BUILD_NUMBER} .
- docker push $IMAGE_NAME

- step: &Deploy
image:
name: atlassian/default-image:2
name: Deploy Image
trigger: manual
script:
- sed -i "s|{{image}}|$IMAGE_NAME|g" aks-deployment.yaml
- pipe: microsoft/azure-aks-deploy:1.0.2
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
AZURE_AKS_NAME: $AZURE_AKS_NAME
AZURE_RESOURCE_GROUP: $AZURE_RESOURCE_GROUP
KUBECTL_COMMAND: 'apply'
KUBECTL_ARGUMENTS: '-f aks-deployment.yaml'




aks-deployment.yaml

containers:
- name: containername
image: {{image}}
imagePullPolicy: IfNotPresent


on trying to deploy this am getting error like 

'The CronJob "jobname" is invalid: spec.jobTemplate.spec.template.spec.containers[0].image: Required value'

Can someone please help with this.
Thanks in advance !

1 answer

1 accepted

0 votes
Answer accepted

Hi @Reethu

Thank you for your question!

To make image name flexible try envsubst (the program substitutes the values of environment variables) instead:

 

- envsubst < aks-deployment.yaml.template > aks-deployment.yaml

Add to your repository template aks-deployment.yaml.template file:

containers:
- name: containername
image: ${IMAGE_NAME}
imagePullPolicy: IfNotPresent

Note! Make sure that ${IMAGE_NAME} exists in the step environment.

Also, good example provided in example-google-gke-kubectl-run repository.

 

Cheers,
Oleksandr Kyrdan

Note!  For future maintenance purposes we have forked the microsoft/azure-aks-deploy pipe from https://bitbucket.org/microsoft/azure-aks-deploy.

Now it is available as atlassian/azure-aks-deploy:1.0.2:

script:
  - pipe: atlassian/azure-aks-deploy:1.0.2
    variables:
      AZURE_APP_ID: $AZURE_APP_ID
      AZURE_PASSWORD: $AZURE_PASSWORD
      AZURE_TENANT_ID: $AZURE_TENANT_ID
      AZURE_AKS_NAME: 'my-cluster'
      AZURE_RESOURCE_GROUP: 'my-resource-group'
      KUBECTL_COMMAND: 'version'

 

To discover more pipes, visit our Bitbucket Pipes Marketplace.

Thanks Oleksandr .

- step: &Deploy
image:
name: atlassian/default-image:2
name: Deploy Image
trigger: manual
script:
- export Build_Id=${BITBUCKET_BUILD_NUMBER}
- envsubst < aks-deployment.yaml > aks.yaml
- pipe: atlassian/azure-aks-deploy:1.0.2
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
AZURE_AKS_NAME: $AZURE_AKS_NAME
AZURE_RESOURCE_GROUP: $AZURE_RESOURCE_GROUP
KUBECTL_COMMAND: 'apply'
KUBECTL_ARGUMENTS: '-f aks.yaml'
DEBUG: 'true'



I have aks-deployment.yaml in my repository with the  variable ${Build_Id}
 

Yep, it's better to create the template file in your repository.

You don't need destination file anymore.

Destination file will be generated automatically on each build.

Like Reethu likes this

Thanks Oleksandr.  I was not aware of the fact that Destination file will be generated automatically on each build.

It worked for me now !!

Like Oleksandr Kyrdan likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

Bitbucket Pipelines Runners is now in open beta

We are excited to announce the open beta program for self-hosted runners. Bitbucket Pipelines Runners is available to everyone. Please try it and let us know your feedback. If you have any issue...

3,902 views 68 21
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