Parameteerizing the Kubernetes namespace k8s manifest deploy task - Azure DevOps - YAML

Shyam Kumar 846 Reputation points
2025-04-22T17:10:01.5866667+00:00

When I ran my YAML pipeline I should select the namespace and run it, default name space should be given as default.

Please suggest how it can be done.

User's image

Azure DevOps
0 comments No comments
{count} votes

Accepted answer
  1. Arko 4,150 Reputation points Microsoft External Staff Moderator
    2025-04-23T07:56:05.6333333+00:00

    Hello Diptesh Kumar,

    You can parameterize the Kubernetes namespace in your DevOps YAML pipeline by using the parameters: block at the top of the YAML file. This allows you to enter a namespace during runtime, with a default fallback (in my example default).

    enter image description here

    example-

    
    parameters:
    
    - name: k8sNamespace
    
      displayName: 'Kubernetes Namespace'
    
      type: string
    
      default: 'default'
    
    variables:
    
      imagePullSecret: acr-secret
    
      dockerRegistryServiceConnection: myDockerRegistrySC
    
      containerRegistry: acrk8stest2039.azurecr.io
    
      imageRepository: demo
    
      tag: latest
    
    stages:
    
    - stage: Deploy
    
      jobs:
    
      - job: DeployJob
    
        steps:
    
        - task: KubernetesManifest@0
    
          displayName: 'Create imagePullSecret'
    
          inputs:
    
            action: createSecret
    
            secretName: $(imagePullSecret)
    
            namespace: ${{ parameters.k8sNamespace }}
    
            dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
    
        - task: KubernetesManifest@0
    
          displayName: 'Deploy App'
    
          inputs:
    
            action: deploy
    
            namespace: ${{ parameters.k8sNamespace }}
    
            manifests: |
    
              $(Build.SourcesDirectory)/manifests/deployment.yml
    
            imagePullSecrets: |
    
              $(imagePullSecret)
    
            containers: |
    
              $(containerRegistry)/$(imageRepository):$(tag)
    
    

    Run the pipeline. it should trigger.

    enter image description here

    Reference links from MS

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.