Kubernetes@1 - Kubectl v1 工作
執行 kubectl 命令,在 Azure Container Service 中部署、設定、更新 Kubernetes 叢集。
執行 kubectl 命令,在 Azure Container Service 中部署、設定、更新 Kubernetes 叢集。
語法
# Kubectl v1
# Deploy, configure, update a Kubernetes cluster in Azure Container Service by running kubectl commands.
- task: Kubernetes@1
inputs:
# Kubernetes Cluster
#connectionType: 'Kubernetes Service Connection' # 'Azure Resource Manager' | 'Kubernetes Service Connection' | 'None'. Required when command != logout. Service connection type. Default: Kubernetes Service Connection.
#kubernetesServiceEndpoint: # string. Required when connectionType = Kubernetes Service Connection && command != logout. Kubernetes service connection.
#azureSubscriptionEndpoint: # string. Required when connectionType = Azure Resource Manager && command != logout. Azure subscription.
#azureResourceGroup: # string. Required when connectionType = Azure Resource Manager && command != logout. Resource group.
#kubernetesCluster: # string. Required when connectionType = Azure Resource Manager && command != logout. Kubernetes cluster.
#useClusterAdmin: false # boolean. Optional. Use when connectionType = Azure Resource Manager && command != logout. Use cluster admin credentials. Default: false.
#namespace: # string. Optional. Use when command != logout. Namespace.
# Commands
#command: # 'apply' | 'create' | 'delete' | 'exec' | 'expose' | 'get' | 'login' | 'logout' | 'logs' | 'run' | 'set' | 'top'. Command.
#useConfigurationFile: false # boolean. Optional. Use when command != login && command != logout. Use configuration. Default: false.
#configurationType: 'configuration' # 'configuration' | 'inline'. Optional. Use when useConfigurationFile = true. Configuration type. Default: configuration.
configuration: # string. Required when configurationType = configuration. File path.
#inline: # string. Required when configurationType = inline. Inline configuration.
#arguments: # string. Optional. Use when command != login && command != logout. Arguments.
# Secrets
#secretType: 'dockerRegistry' # 'dockerRegistry' | 'generic'. Required when command != login && command != logout. Type of secret. Default: dockerRegistry.
#secretArguments: # string. Optional. Use when secretType = generic && command != login && command != logout. Arguments.
#containerRegistryType: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required when secretType = dockerRegistry && command != login && command != logout. Container registry type. Default: Azure Container Registry.
#dockerRegistryEndpoint: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Container Registry && command != login && command != logout. Docker registry service connection.
#azureSubscriptionEndpointForSecrets: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure container registry.
#secretName: # string. Optional. Use when command != login && command != logout. Secret name.
#forceUpdate: true # boolean. Optional. Use when command != login && command != logout. Force update secret. Default: true.
# ConfigMaps
#configMapName: # string. Optional. Use when command != login && command != logout. ConfigMap name.
#forceUpdateConfigMap: false # boolean. Optional. Use when command != login && command != logout. Force update configmap. Default: false.
#useConfigMapFile: false # boolean. Optional. Use when command != login && command != logout. Use file. Default: false.
#configMapFile: # string. Required when useConfigMapFile = true && command != login && command != logout. ConfigMap file.
#configMapArguments: # string. Optional. Use when useConfigMapFile = false && command != login && command != logout. Arguments.
# Advanced
#versionOrLocation: 'version' # 'version' | 'location'. Kubectl. Default: version.
#versionSpec: '1.13.2' # string. Optional. Use when versionOrLocation = version. Version spec. Default: 1.13.2.
#checkLatest: false # boolean. Optional. Use when versionOrLocation = version. Check for latest version. Default: false.
#specifyLocation: # string. Required when versionOrLocation = location. Path to kubectl.
#workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working directory. Default: $(System.DefaultWorkingDirectory).
#outputFormat: 'json' # 'json' | 'yaml' | 'none'. Output format. Default: json.
# Kubectl v1
# Deploy, configure, update a Kubernetes cluster in Azure Container Service by running kubectl commands.
- task: Kubernetes@1
inputs:
# Kubernetes Cluster
#connectionType: 'Kubernetes Service Connection' # 'Azure Resource Manager' | 'Kubernetes Service Connection' | 'None'. Required when command != logout. Service connection type. Default: Kubernetes Service Connection.
#kubernetesServiceEndpoint: # string. Required when connectionType = Kubernetes Service Connection && command != logout. Kubernetes service connection.
#azureSubscriptionEndpoint: # string. Required when connectionType = Azure Resource Manager && command != logout. Azure subscription.
#azureResourceGroup: # string. Required when connectionType = Azure Resource Manager && command != logout. Resource group.
#kubernetesCluster: # string. Required when connectionType = Azure Resource Manager && command != logout. Kubernetes cluster.
#useClusterAdmin: false # boolean. Optional. Use when connectionType = Azure Resource Manager && command != logout. Use cluster admin credentials. Default: false.
#namespace: # string. Optional. Use when command != logout. Namespace.
# Commands
#command: # 'apply' | 'create' | 'delete' | 'exec' | 'expose' | 'get' | 'login' | 'logout' | 'logs' | 'run' | 'set' | 'top'. Command.
#useConfigurationFile: false # boolean. Optional. Use when command != login && command != logout. Use configuration. Default: false.
#configurationType: 'configuration' # 'configuration' | 'inline'. Optional. Use when useConfigurationFile = true. Configuration type. Default: configuration.
configuration: # string. Required when configurationType = configuration. File path.
#inline: # string. Required when configurationType = inline. Inline configuration.
#arguments: # string. Optional. Use when command != login && command != logout. Arguments.
# Secrets
#secretType: 'dockerRegistry' # 'dockerRegistry' | 'generic'. Required when command != login && command != logout. Type of secret. Default: dockerRegistry.
#secretArguments: # string. Optional. Use when secretType = generic && command != login && command != logout. Arguments.
#containerRegistryType: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required when secretType = dockerRegistry && command != login && command != logout. Container registry type. Default: Azure Container Registry.
#dockerRegistryEndpoint: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Container Registry && command != login && command != logout. Docker registry service connection.
#azureSubscriptionEndpointForSecrets: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure container registry.
#secretName: # string. Optional. Use when command != login && command != logout. Secret name.
#forceUpdate: true # boolean. Optional. Use when command != login && command != logout. Force update secret. Default: true.
# ConfigMaps
#configMapName: # string. Optional. Use when command != login && command != logout. ConfigMap name.
#forceUpdateConfigMap: false # boolean. Optional. Use when command != login && command != logout. Force update configmap. Default: false.
#useConfigMapFile: false # boolean. Optional. Use when command != login && command != logout. Use file. Default: false.
#configMapFile: # string. Required when useConfigMapFile = true && command != login && command != logout. ConfigMap file.
#configMapArguments: # string. Optional. Use when useConfigMapFile = false && command != login && command != logout. Arguments.
# Advanced
#versionOrLocation: 'version' # 'version' | 'location'. Kubectl. Default: version.
#versionSpec: '1.13.2' # string. Optional. Use when versionOrLocation = version. Version spec. Default: 1.13.2.
#checkLatest: false # boolean. Optional. Use when versionOrLocation = version. Check for latest version. Default: false.
#specifyLocation: # string. Required when versionOrLocation = location. Path to kubectl.
#workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working directory. Default: $(System.DefaultWorkingDirectory).
#outputFormat: 'json' # 'json' | 'yaml'. Output format. Default: json.
# Deploy to Kubernetes v1
# Deploy, configure, update a Kubernetes cluster in Azure Container Service by running kubectl commands.
- task: Kubernetes@1
inputs:
# Kubernetes Cluster
#connectionType: 'Kubernetes Service Connection' # 'Azure Resource Manager' | 'Kubernetes Service Connection' | 'None'. Required when command != logout. Service connection type. Default: Kubernetes Service Connection.
#kubernetesServiceEndpoint: # string. Required when connectionType = Kubernetes Service Connection && command != logout. Kubernetes service connection.
#azureSubscriptionEndpoint: # string. Required when connectionType = Azure Resource Manager && command != logout. Azure subscription.
#azureResourceGroup: # string. Required when connectionType = Azure Resource Manager && command != logout. Resource group.
#kubernetesCluster: # string. Required when connectionType = Azure Resource Manager && command != logout. Kubernetes cluster.
#useClusterAdmin: false # boolean. Optional. Use when connectionType = Azure Resource Manager && command != logout. Use cluster admin credentials. Default: false.
#namespace: # string. Optional. Use when command != logout. Namespace.
# Commands
#command: # 'apply' | 'create' | 'delete' | 'exec' | 'expose' | 'get' | 'login' | 'logout' | 'logs' | 'run' | 'set' | 'top'. Command.
#useConfigurationFile: false # boolean. Optional. Use when command != login && command != logout. Use configuration. Default: false.
#configurationType: 'configuration' # 'configuration' | 'inline'. Optional. Use when useConfigurationFile = true. Configuration type. Default: configuration.
configuration: # string. Required when configurationType = configuration. File path.
#inline: # string. Required when configurationType = inline. Inline configuration.
#arguments: # string. Optional. Use when command != login && command != logout. Arguments.
# Secrets
#secretType: 'dockerRegistry' # 'dockerRegistry' | 'generic'. Required when command != login && command != logout. Type of secret. Default: dockerRegistry.
#secretArguments: # string. Optional. Use when secretType = generic && command != login && command != logout. Arguments.
#containerRegistryType: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required when secretType = dockerRegistry && command != login && command != logout. Container registry type. Default: Azure Container Registry.
#dockerRegistryEndpoint: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Container Registry && command != login && command != logout. Docker registry service connection.
#azureSubscriptionEndpointForSecrets: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure container registry.
#secretName: # string. Optional. Use when command != login && command != logout. Secret name.
#forceUpdate: true # boolean. Optional. Use when command != login && command != logout. Force update secret. Default: true.
# ConfigMaps
#configMapName: # string. Optional. Use when command != login && command != logout. ConfigMap name.
#forceUpdateConfigMap: false # boolean. Optional. Use when command != login && command != logout. Force update configmap. Default: false.
#useConfigMapFile: false # boolean. Optional. Use when command != login && command != logout. Use file. Default: false.
#configMapFile: # string. Required when useConfigMapFile = true && command != login && command != logout. ConfigMap file.
#configMapArguments: # string. Optional. Use when useConfigMapFile = false && command != login && command != logout. Arguments.
# Advanced
#versionOrLocation: 'version' # 'version' | 'location'. Kubectl. Default: version.
#versionSpec: '1.13.2' # string. Optional. Use when versionOrLocation = version. Version spec. Default: 1.13.2.
#checkLatest: false # boolean. Optional. Use when versionOrLocation = version. Check for latest version. Default: false.
#specifyLocation: # string. Required when versionOrLocation = location. Path to kubectl.
#workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working directory. Default: $(System.DefaultWorkingDirectory).
#outputFormat: 'json' # 'json' | 'yaml'. Output format. Default: json.
# Deploy to Kubernetes v1
# Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.
- task: Kubernetes@1
inputs:
# Kubernetes Cluster
#connectionType: 'Azure Resource Manager' # 'Azure Resource Manager' | 'Kubernetes Service Connection' | 'None'. Required when command != logout. Service connection type. Default: Azure Resource Manager.
#kubernetesServiceEndpoint: # string. Required when connectionType = Kubernetes Service Connection && command != logout. Kubernetes service connection.
#azureSubscriptionEndpoint: # string. Required when connectionType = Azure Resource Manager && command != logout. Azure subscription.
#azureResourceGroup: # string. Required when connectionType = Azure Resource Manager && command != logout. Resource group.
#kubernetesCluster: # string. Required when connectionType = Azure Resource Manager && command != logout. Kubernetes cluster.
#namespace: # string. Optional. Use when command != logout. Namespace.
# Commands
command: 'apply' # 'apply' | 'create' | 'delete' | 'exec' | 'expose' | 'get' | 'login' | 'logout' | 'logs' | 'run' | 'set' | 'top'. Required. Command. Default: apply.
#useConfigurationFile: false # boolean. Optional. Use when command != login && command != logout. Use configuration files. Default: false.
#configuration: # string. Required when useConfigurationFile = true. Configuration file.
#arguments: # string. Optional. Use when command != login && command != logout. Arguments.
# Secrets
#secretType: 'dockerRegistry' # 'dockerRegistry' | 'generic'. Required when command != login && command != logout. Type of secret. Default: dockerRegistry.
#secretArguments: # string. Optional. Use when secretType = generic && command != login && command != logout. Arguments.
#containerRegistryType: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required when secretType = dockerRegistry && command != login && command != logout. Container registry type. Default: Azure Container Registry.
#dockerRegistryEndpoint: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Container Registry && command != login && command != logout. Docker registry service connection.
#azureSubscriptionEndpointForSecrets: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout. Azure container registry.
#secretName: # string. Optional. Use when command != login && command != logout. Secret name.
#forceUpdate: true # boolean. Optional. Use when command != login && command != logout. Force update secret. Default: true.
# ConfigMaps
#configMapName: # string. Optional. Use when command != login && command != logout. ConfigMap name.
#forceUpdateConfigMap: false # boolean. Optional. Use when command != login && command != logout. Force update configmap. Default: false.
#useConfigMapFile: false # boolean. Optional. Use when command != login && command != logout. Use file. Default: false.
#configMapFile: # string. Required when useConfigMapFile = true && command != login && command != logout. ConfigMap file.
#configMapArguments: # string. Optional. Use when useConfigMapFile = false && command != login && command != logout. Arguments.
# Advanced
#versionOrLocation: 'version' # 'version' | 'location'. Optional. Use when command != login && command != logout. Kubectl. Default: version.
#versionSpec: '1.7.0' # string. Optional. Use when versionOrLocation = version && command != login && command != logout. Version spec. Default: 1.7.0.
#checkLatest: false # boolean. Optional. Use when versionOrLocation = version && command != login && command != logout. Check for latest version. Default: false.
#specifyLocation: # string. Required when versionOrLocation = location && command != login && command != logout. Path to kubectl.
#workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Optional. Use when command != login && command != logout. Working directory. Default: $(System.DefaultWorkingDirectory).
#outputFormat: 'json' # 'json' | 'yaml'. Optional. Use when command != login && command != logout. Output format. Default: json.
輸入
connectionType
-
服務連線類型
string
。
command != logout
時為必要項。 允許的值:Azure Resource Manager
、Kubernetes Service Connection
、None
。 預設值:Kubernetes Service Connection
。
指定服務連線類型:針對任何其他叢集使用 Azure Kubernetes Service 或 Kubernetes Service Connection 時的 Azure Resource Manager。
-
Kubernetes Service Connection
- 可讓您提供 KubeConfig 檔案、指定服務帳戶,或使用 Azure 訂用帳戶 選項匯入 AKS 實例。 使用 Azure 訂用帳戶 選項匯入 AKS 實例,需要在服務連線設定時間存取 Kubernetes 叢集。 -
Azure Resource Manager
- 可讓您選取 AKS 實例。 不會在服務連線設定時間存取 Kubernetes 叢集。 -
None
- 使用儲存在本機的預先建立 Kubernetes 組態。
如需詳細資訊,請參閱下列
connectionType
-
服務連線類型
string
。
command != logout
時為必要項。 允許的值:Azure Resource Manager
、Kubernetes Service Connection
、None
。 預設值:Azure Resource Manager
。
指定服務連線類型:針對任何其他叢集使用 Azure Kubernetes Service 或 Kubernetes Service Connection 時的 Azure Resource Manager。
kubernetesServiceEndpoint
-
Kubernetes 服務連線
string
。
connectionType = Kubernetes Service Connection && command != logout
時為必要項。
選取 Kubernetes 服務連線。
azureSubscriptionEndpoint
-
Azure 訂用帳戶
string
。
connectionType = Azure Resource Manager && command != logout
時為必要項。
指定 Azure Resource Manager 訂用帳戶,其中包含 Azure Container Registry。
注意
若要設定新的服務連線,請從清單中指定 Azure 訂用帳戶,然後按兩下 [Authorize
]。 如果您的訂用帳戶未列出,或您想要使用現有的服務主體,您可以使用 Add
或 Manage
按鈕來設定 Azure 服務連線。
azureResourceGroup
-
資源群組
string
。
connectionType = Azure Resource Manager && command != logout
時為必要項。
選取 Azure 資源群組。
kubernetesCluster
-
Kubernetes 叢集
string
。
connectionType = Azure Resource Manager && command != logout
時為必要項。
選取 Azure 受控叢集。
useClusterAdmin
-
使用叢集管理員認證
boolean
。 自選。
connectionType = Azure Resource Manager && command != logout
時使用 。 預設值:false
。
使用叢集管理員認證,而不是預設叢集用戶認證。
namespace
-
命名空間
string
。 自選。
command != logout
時使用 。
使用 –namespace 旗標設定 kubectl 命令的命名空間。 如果未提供命名空間,命令將會在預設命名空間中執行。
command
-
命令
string
。 允許的值:apply
、create
、delete
、exec
、expose
、get
、login
、logout
、logs
、run
、set
top
。
選取或指定要執行的 kubectl 命令。 允許的值清單提供一些常見選項,以在使用工作助理時輕鬆選取,但您可以指定其他 kubectl 命令,例如 scale
。 使用 arguments
輸入,將其他參數指定至指定的 kubectl
命令。
command
-
命令
string
。 必填。 允許的值:apply
、create
、delete
、exec
、expose
、get
、login
、logout
、logs
、run
、set
top
。 預設值:apply
。
選取或指定要執行的 kubectl 命令。
useConfigurationFile
-
使用組態
boolean
。 自選。
command != login && command != logout
時使用 。 預設值:false
。
指定要搭配 kubectl
命令使用的 Kubernetes 組態。 您可以提供 Kubernetes 組態檔的內嵌腳本、檔名、目錄或 URL。
useConfigurationFile
-
使用組態檔
boolean
。 自選。
command != login && command != logout
時使用 。 預設值:false
。
指定要搭配 kubectl
命令使用的 Kubernetes 組態。 您可以提供 Kubernetes 組態檔的內嵌腳本、檔名、目錄或 URL。
configurationType
-
組態類型
string
。 自選。
useConfigurationFile = true
時使用 。 允許的值:configuration
(檔案路徑)、inline
(內嵌組態)。 預設值:configuration
。
指定 kubectl
命令的 Kubernetes 組態類型。 它可以是檔案路徑或內嵌腳本。
configuration
-
檔案路徑
string
。
configurationType = configuration
時為必要項。
指定與命令搭配使用的 kubernetes 組態檔的檔名、目錄或 URL。
configuration
-
組態檔
string
。
useConfigurationFile = true
時為必要項。
指定與命令搭配使用的 kubernetes 組態檔的檔名、目錄或 URL。
inline
-
內嵌組態
string
。
configurationType = inline
時為必要項。
指定 kubectl
命令的內嵌部署組態。
arguments
-
自變數
string
。 自選。
command != login && command != logout
時使用 。
指定 kubectl 命令的自變數。
secretType
-
秘密類型
string
。
command != login && command != logout
時為必要項。 允許的值:dockerRegistry
、generic
。 預設值:dockerRegistry
。
建立/更新泛型或 docker imagepullsecret。 選取 dockerRegistry 以建立/更新所選取登錄的 imagepullsecret。 imagePullSecret 是一種將包含容器登錄密碼的秘密傳遞至 Kubelet 的方式,以便代表您的 Pod 提取私人映像。
secretArguments
-
自變數
string
。 自選。
secretType = generic && command != login && command != logout
時使用 。
指定要在秘密中插入的索引鍵和常值。 例如,--from-literal=key1=value1
或 --from-literal=key2="top secret"
。
containerRegistryType
-
容器登錄類型
string
。
secretType = dockerRegistry && command != login && command != logout
時為必要項。 允許的值:Azure Container Registry
、Container Registry
。 預設值:Azure Container Registry
。
選取容器登錄類型。 工作可以使用 Azure 訂用帳戶詳細數據來處理 Azure Container Registry。 也支援其他標準容器登錄。
dockerRegistryEndpoint
-
Docker 登錄服務連線
string
。 自選。
secretType = dockerRegistry && containerRegistryType = Container Registry && command != login && command != logout
時使用 。
選取 Docker 登錄服務連線。 需要用於需要向登錄進行驗證的命令。
azureSubscriptionEndpointForSecrets
-
Azure 訂用帳戶
string
。 自選。
secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout
時使用 。
指定包含 Azure Container Registry 的 Azure Resource Manager 訂用帳戶。
注意
若要設定新的服務連線,請從清單中選取 Azure 訂用帳戶,然後按兩下 [Authorize
]。 如果您的訂用帳戶未列出,或您想要使用現有的服務主體,您可以使用 Add
或 Manage
按鈕來設定 Azure 服務連線。
azureContainerRegistry
-
Azure Container Registry
string
。 自選。
secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout
時使用 。
指定用來提取容器映像並將應用程式部署至 Kubernetes 叢集的 Azure Container Registry。 需要用於需要向登錄進行驗證的命令。
secretName
-
秘密名稱
string
。 自選。
command != login && command != logout
時使用 。
秘密的名稱。 您可以在 Kubernetes YAML 組態檔中使用這個秘密名稱。
forceUpdate
-
強制更新秘密
boolean
。 自選。
command != login && command != logout
時使用 。 預設值:true
。
如果秘密存在,請刪除秘密,並建立具有更新值的新密碼。
configMapName
-
ConfigMap 名稱
string
。 自選。
command != login && command != logout
時使用 。
ConfigMap 可讓您將設定成品與映像內容分離,讓容器化應用程式保持可移植性。
forceUpdateConfigMap
-
強制更新 configmap
boolean
。 自選。
command != login && command != logout
時使用 。 預設值:false
。
如果存在,請刪除 configmap,並建立具有更新值的新組態圖。
useConfigMapFile
-
使用檔案
boolean
。 自選。
command != login && command != logout
時使用 。 預設值:false
。
藉由指定目錄,從個別檔案或從多個檔案建立 ConfigMap
。
configMapFile
-
ConfigMap 檔案
string
。
useConfigMapFile = true && command != login && command != logout
時為必要項。
指定包含 configMap 的檔案或目錄。
configMapArguments
-
自變數
string
。 自選。
useConfigMapFile = false && command != login && command != logout
時使用 。
指定要在 configMap
中插入的索引鍵和常值。 例如,--from-literal=key1=value1
或 --from-literal=key2="top secret"
。
versionOrLocation
-
Kubectl
string
。 允許的值:version
、location
(指定位置)。 預設值:version
。
kubectl 是針對 Kubernetes 叢集執行命令的命令行介面。
versionOrLocation
-
Kubectl
string
。 自選。
command != login && command != logout
時使用 。 允許的值:version
、location
(指定位置)。 預設值:version
。
kubectl 是針對 Kubernetes 叢集執行命令的命令行介面。
versionSpec
-
版本規格
string
。 自選。
versionOrLocation = version
時使用 。 預設值:1.13.2
。
指定要取得的版本規格。 範例:1.7.0
、1.x.0
、4.x.0
、6.10.0
>=6.10.0
。
versionSpec
-
版本規格
string
。 自選。
versionOrLocation = version && command != login && command != logout
時使用 。 預設值:1.7.0
。
-18-2 指定要取得的版本規格。 範例:1.7.0
、1.x.0
、4.x.0
、6.10.0
>=6.10.0
。
checkLatest
-
檢查最新版本
boolean
。 自選。
versionOrLocation = version
時使用 。 預設值:false
。
請一律在線檢查符合版本規格的最新可用版本(stable.txt)。除非您有特定案例隨時取得最新情況,否則這通常為 false。 這會導致它在必要時產生下載成本,特別是裝載的組建集區。
checkLatest
-
檢查最新版本
boolean
。 自選。
versionOrLocation = version && command != login && command != logout
時使用 。 預設值:false
。
請一律在線檢查符合版本規格的最新可用版本(stable.txt)。除非您有特定案例隨時取得最新情況,否則這通常為 false。 這會導致它在必要時產生下載成本,特別是裝載的組建集區。
specifyLocation
-
kubectl 路徑
string
。
versionOrLocation = location
時為必要項。
指定 kubectl.exe
檔案的完整路徑。
specifyLocation
-
kubectl 路徑
string
。
versionOrLocation = location && command != login && command != logout
時為必要項。
指定 kubectl.exe
檔案的完整路徑。
workingDirectory
-
工作目錄
輸入別名:cwd
。
string
。 預設值:$(System.DefaultWorkingDirectory)
。
Kubectl 命令的工作目錄。
workingDirectory
-
工作目錄
輸入別名:cwd
。
string
。 自選。
command != login && command != logout
時使用 。 預設值:$(System.DefaultWorkingDirectory)
。
Kubectl 命令的工作目錄。
outputFormat
-
輸出格式
string
。 允許的值:json
、yaml
、none
。 預設值:json
。
輸出格式。 允許的值清單提供一些常見的選項,讓您在使用工作助理時輕鬆選取,但您可以指定其他 輸出選項, 例如 jsonpath={.items[*].spec['initContainers', 'containers'][*].image}
。
outputFormat
-
輸出格式
string
。 允許的值:json
、yaml
。 預設值:json
。
輸出格式。 允許的值清單提供一些常見的選項,讓您在使用工作助理時輕鬆選取,但您可以指定其他 輸出選項, 例如 jsonpath={.items[*].spec['initContainers', 'containers'][*].image}
。
outputFormat
-
輸出格式
string
。 自選。
command != login && command != logout
時使用 。 允許的值:json
、yaml
。 預設值:json
。
輸出格式。 允許的值清單提供一些常見的選項,讓您在使用工作助理時輕鬆選取,但您可以指定其他 輸出選項, 例如 jsonpath={.items[*].spec['initContainers', 'containers'][*].image}
。
工作控制選項
除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制項選項和一般工作屬性。
輸出變數
此工作會定義下列 輸出變數,您可以在下游步驟、作業和階段中取用這些變數。
KubectlOutput
儲存 kubectl
命令的輸出。
言論
1.0 版的新功能。
- 已新增服務連線類型輸入,以便輕鬆選取 Azure AKS 叢集。
- 以我們在所有工作中新增的輸出變數區段取代輸出變數輸入。
使用此工作執行 kubectl 命令來部署、設定或更新 Kubernetes 叢集。
服務連線
此工作適用於兩種服務連線類型:Azure Resource Manager 和 Kubernetes Service Connection,如下所述。
Azure Resource Manager
將 connectionType
設定為 Azure Resource Manager
,並指定使用 Azure Resource Manager 服務連線的 azureSubscriptionEndpoint
。
此 YAML 範例示範如何使用 Azure Resource Manager 來參考 Kubernetes 叢集。 這是與其中一個 kubectl 命令搭配使用, 和命令所需的適當值。
variables:
azureSubscriptionEndpoint: Contoso
azureContainerRegistry: contoso.azurecr.io
azureResourceGroup: Contoso
kubernetesCluster: Contoso
useClusterAdmin: false
steps:
- task: Kubernetes@1
displayName: kubectl apply
inputs:
connectionType: Azure Resource Manager
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
useClusterAdmin: $(useClusterAdmin)
Kubernetes Service 連線
將 connectionType
設定為 Kubernetes Service Connection
,並指定要使用 Kubernetes 服務連線的 kubernetesServiceEndpoint
。
此 YAML 範例示範如何使用 Kubernetes Service 連線來參考 Kubernetes 叢集。 這是與其中一個 kubectl 命令搭配使用, 和命令所需的適當值。
- task: Kubernetes@1
displayName: kubectl apply
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: Contoso
存取 AKS 時的 Kubernetes Service 連線考慮
您可以使用下列任何選項來建立 Kubernetes 服務連線。
- KubeConfig
- 服務帳戶
- Azure 訂用帳戶
選取 [Azure 訂用帳戶] 選項時,必須在服務連線設定時間存取 Azure DevOps。 可能無法建立服務連線的各種原因,例如,建立私人叢集 或叢集 本機帳戶已停用。 在這些情況下,Azure DevOps 無法在服務連線設定時間連線到您的叢集,您會看到停滯 載入命名空間 畫面。
從 Kubernetes 1.24 開始,預設 不會再建立長期令牌。 Kubernetes 建議不要使用長期令牌。 因此,使用以 Azure 訂用帳戶 選項建立的 Kubernetes 服務連線的工作無法存取驗證所需的永久令牌,且無法存取 Kubernetes 叢集。 這也會導致凍結 載入命名空間 對話框。
使用 Azure Resource Manager 服務連線來存取 AKS
對於 AKS 客戶,Azure Resource Manager 服務連線類型提供連線至私人叢集的最佳方法,或已停用本機帳戶的叢集。 當您建立服務連線時,此方法不相依於叢集連線。 AKS 的存取會延後至管線運行時間,其優點如下:
- 您可以從可看見叢集的自我裝載或擴展集代理程式,存取 (private) AKS 叢集。
- 系統會針對使用 Azure Resource Manager 服務連線的每個工作建立令牌。 這可確保您使用短期令牌連線到 Kubernetes,這是 Kubernetes 建議。
- 即使停用本機帳戶,也可以存取 AKS。
服務連線常見問題
我收到下列錯誤訊息:找不到與服務帳戶相關聯的任何秘密。 發生了什麼事情?
您使用 Kubernetes 服務連線與 Azure 訂用帳戶選項。 我們正在更新此方法來建立長期保存的令牌。 這預計將在5月中旬提供。 不過,建議您開始使用 Azure 服務連線類型,而不是根據 Kubernetes 指引使用長期令牌。
我使用的是 AKS,而且不想變更任何專案,我是否可以繼續搭配 Kubernetes 服務連線使用工作?
我們正在更新此方法來建立長期保存的令牌。 這預計將在5月中旬提供。 不過,請注意,此方法是針對 Kubernetes 指引。
我使用的是 Kubernetes 工作和 Kubernetes 服務連線,但不是 AKS。 我應該擔心嗎?
您的工作會如往年一樣繼續運作。
是否會移除 Kubernetes 服務連線類型?
不論其執行位置為何,Kubernetes 工作都會與任何 Kubernetes 叢集搭配運作。 Kubernetes 服務連線將繼續存在。
我是 AKS 客戶,一切都正常運作,我應該採取行動嗎?
不需要變更任何專案。 如果您在建立期間使用 Kubernetes 服務連線和選取的 Azure 訂用帳戶,您應該瞭解使用長期令牌的 Kubernetes 指引。
我正在建立 Kubernetes 環境,而且沒有使用服務連線的選項
如果您在環境建立期間無法存取 AKS,您可以使用空的環境,並將 connectionType
輸入設定為 Azure Resource Manager 服務連線。
我已使用 Azure Active Directory RBAC 設定 AKS,且我的管線無法運作。 這些更新會解決此問題嗎?
啟用 AAD RBAC 時存取 Kubernetes 與令牌建立無關。 為了防止互動式提示,我們將在未來的更新中支援 kubelogin。
命令
此 YAML 範例示範 套用 命令:
- task: Kubernetes@1
displayName: kubectl apply using arguments
inputs:
connectionType: Azure Resource Manager
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
command: apply
arguments: -f mhc-aks.yaml
此 YAML 範例示範如何使用組態檔搭配 apply 命令:
- task: Kubernetes@1
displayName: kubectl apply using configFile
inputs:
connectionType: Azure Resource Manager
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
command: apply
useConfigurationFile: true
configuration: mhc-aks.yaml
此 YAML 範例示範如何使用 縮放比例 命令,將部署中的複本數目減少為 0。
- task: Kubernetes@1
displayName: 'Scale down deployment $(k8sDeployment) to 0'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: $(kubernetesServiceConnection)
command: 'scale'
arguments: 'deployment/$(k8sDeployment) --replicas=0'
namespace: $(namespace)
秘密
秘密 類型的 Kubernetes 物件旨在保存機密資訊,例如密碼、OAuth 令牌和 ssh 金鑰。 將此資訊放在秘密中比在Pod定義或Docker映像中逐字放置更安全且更有彈性。 Azure Pipelines 可簡化將 ImagePullSecrets
新增至服務帳戶,或設定任何一般秘密,如下所述。
ImagePullSecret
此 YAML 範例示範 ImagePullSecrets 的設定:
- task: Kubernetes@1
displayName: kubectl apply for secretType dockerRegistry
inputs:
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
command: apply
arguments: -f mhc-aks.yaml
secretType: dockerRegistry
containerRegistryType: Azure Container Registry
azureSubscriptionEndpointForSecrets: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
secretName: mysecretkey2
forceUpdate: true
一般秘密
此 YAML 範例會從輸入 secretArgument s 指定的常值建立泛型秘密:
- task: Kubernetes@1
displayName: secretType generic with literal values
inputs:
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
command: apply
arguments: -f mhc-aks.yaml
secretType: generic
secretArguments: --from-literal=contoso=5678
secretName: mysecretkey
管線變數可用來傳遞自變數來指定常值,如下所示:
- task: Kubernetes@1
displayName: secretType generic with pipeline variables
inputs:
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
command: apply
arguments: -f mhc-aks.yaml
secretType: generic
secretArguments: --from-literal=contoso=$(contosovalue)
secretName: mysecretkey
ConfigMap
ConfigMap 可讓您將設定成品與映像內容分離,以維護容器化應用程式的可移植性。
此 YAML 範例會指向 ConfigMap 檔案來建立 ConfigMap:
- task: Kubernetes@1
displayName: kubectl apply
inputs:
configMapName: myconfig
useConfigMapFile: true
configMapFile: src/configmap
此 YAML 範例會直接將常值指定為 configMapArguments 輸入,並將 forceUpdate 設定為 true 來建立 ConfigMap:
- task: Kubernetes@1
displayName: configMap with literal values
inputs:
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
command: apply
arguments: -f mhc-aks.yaml
secretType: generic
secretArguments: --from-literal=contoso=$(contosovalue)
secretName: mysecretkey4
configMapName: myconfig
forceUpdateConfigMap: true
configMapArguments: --from-literal=myname=contoso
您可以在建立 ConfigMap 時使用管線變數來傳遞常值,如下所示:
- task: Kubernetes@1
displayName: configMap with pipeline variables
inputs:
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureResourceGroup: $(azureResourceGroup)
kubernetesCluster: $(kubernetesCluster)
command: apply
arguments: -f mhc-aks.yaml
secretType: generic
secretArguments: --from-literal=contoso=$(contosovalue)
secretName: mysecretkey4
configMapName: myconfig
forceUpdateConfigMap: true
configMapArguments: --from-literal=myname=$(contosovalue)
故障排除
我的 Kubernetes 叢集位於防火牆後方,而我使用的是託管的代理程式。 如何部署至此叢集?
您可以允許託管代理程式的IP位址,透過防火牆授與託管代理程式的存取權。 如需詳細資訊,請參閱 代理程式IP範圍
要求
要求 | 描述 |
---|---|
管線類型 | YAML、傳統組建、傳統版本 |
執行於 | Agent、DeploymentGroup |
需求 | 沒有 |
功能 | 此工作不符合作業中後續工作的任何需求。 |
命令限制 | 任何 |
Settable 變數 | 任何 |
代理程式版本 | 所有支援的代理程式版本。 |
工作類別 | 部署 |