【问题标题】:Azure pipeline - How to execute kubectl commandAzure 管道 - 如何执行 kubectl 命令
【发布时间】:2021-08-30 07:01:04
【问题描述】:

我正在尝试删除所有以“dev-...”为前缀的命名空间。该命令在命令行上运行良好,但我不确定如何在 Azure Pipelines 中运行。

kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep dev- | xargs kubectl delete namespace

【问题讨论】:

    标签: azure kubernetes azure-pipelines kubectl


    【解决方案1】:

    您好,下面的管道应该与定义的服务主体一起使用。

    trigger: none
    
    pool:
      vmImage: 'ubuntu-latest'
    
    steps:
    
    # Delete All namespaces start with dev-
    - task: AzureCLI@2
      inputs:
        azureSubscription: 'YOUR_SUBSCRIPTION_SP'
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: |
          az aks get-credentials --resource-group $AKS_RG --name $AKS_NAME --admin
          kubectl get ns
          kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep dev- | xargs kubectl delete namespace
          kubectl get ns
      displayName: 'Delete All namespaces start with dev-'
    

    【讨论】:

    • 很高兴听到这个消息!您可以将其标记为社区的答案;)
    • 这个答案是救命稻草^^谢谢
    猜你喜欢
    • 2020-09-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    • 2020-04-26
    • 1970-01-01
    • 2020-04-02
    相关资源
    最近更新 更多