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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,467,920
Community Members
 
Community Events
177
Community Groups

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

Atlassian Community Events