Kubernetes@1 - Kubectl v1 任务
通过运行 kubectl 命令在 Azure 容器服务中部署、配置和更新 Kubernetes 群集。
通过运行 kubectl 命令在 Azure 容器服务中部署、配置和更新 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 服务或 Kubernetes 服务连接时的 Azure 资源管理器。
-
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 服务或 Kubernetes 服务连接时的 Azure 资源管理器。
kubernetesServiceEndpoint
-
Kubernetes 服务连接
string
。
connectionType = Kubernetes Service Connection && command != logout
时是必需的。
选择 Kubernetes 服务连接。
azureSubscriptionEndpoint
-
Azure 订阅
string
。
connectionType = Azure Resource Manager && command != logout
时是必需的。
指定包含 Azure 容器注册表的 Azure 资源管理器订阅。
注意
若要配置新的服务连接,请从列表中选择 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 容器注册表。 还支持其他标准容器注册表。
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 容器注册表的 Azure 资源管理器订阅。
注意
若要配置新的服务连接,请从列表中选择 Azure 订阅,然后单击 Authorize
。 如果订阅未列出,或者想要使用现有服务主体,则可以使用 Add
或 Manage
按钮设置 Azure 服务连接。
azureContainerRegistry
-
Azure 容器注册表
string
。 自选。 当 secretType = dockerRegistry && containerRegistryType = Azure Container Registry && command != login && command != logout
时使用。
指定一个 Azure 容器注册表,用于拉取容器映像并将应用程序部署到 Kubernetes 群集。 需要使用注册表进行身份验证的命令。
secretName
-
机密名称
string
。 自选。 当 command != login && command != logout
时使用。
机密的名称。 可以在 Kubernetes YAML 配置文件中使用此机密名称。
forceUpdate
-
强制更新机密
boolean
。 自选。 当 command != login && command != logout
时使用。 默认值:true
。
如果机密存在,请将其删除,并创建一个具有更新值的新机密。
configMapName
-
ConfigMap 名称
string
。 自选。 当 command != login && command != logout
时使用。
ConfigMaps 允许将配置项目与映像内容分离,使容器化应用程序保持可移植性。
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 资源管理器 和 Kubernetes 服务连接,如下所述。
Azure 资源管理器
将 connectionType
设置为 Azure Resource Manager
,并指定使用 Azure 资源管理器服务连接的 azureSubscriptionEndpoint
。
此 YAML 示例演示如何使用 Azure 资源管理器来引用 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 服务连接
将 connectionType
设置为 Kubernetes Service Connection
,并指定使用 Kubernetes 服务连接的 kubernetesServiceEndpoint
。
此 YAML 示例演示如何使用 Kubernetes 服务连接来引用 Kubernetes 群集。 这与 kubectl 命令之一 以及命令所需的适当值一起使用。
- task: Kubernetes@1
displayName: kubectl apply
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: Contoso
访问 AKS 时的 Kubernetes 服务连接注意事项
可以使用以下任一选项创建 Kubernetes 服务连接。
- KubeConfig
- 服务帐户
- Azure 订阅
选择 Azure 订阅 选项时,需要在服务连接配置时访问 Kubernetes。 创建服务连接的原因可能有多种,例如,创建专用群集 或者群集 本地帐户已禁用。 在这些情况下,Azure DevOps 无法在服务连接配置时连接到群集,你将看到 加载命名空间 屏幕停滞。
从 Kubernetes 1.24 开始,长期令牌在默认情况下 不再创建。 Kubernetes 建议不要使用生存期较长的令牌。 因此,使用通过 Azure 订阅创建的 Kubernetes 服务连接的任务 选项无权访问身份验证所需的永久令牌,并且无法访问 Kubernetes 群集。 这还会导致冻结 加载命名空间 对话框。
使用 Azure 资源管理器服务连接访问 AKS
对于 AKS 客户,Azure 资源管理器服务连接类型提供了连接到专用群集或禁用本地帐户的群集的最佳方法。 此方法不依赖于创建服务连接时的群集连接。 对 AKS 的访问将延迟到管道运行时,这具有以下优势:
- 可以从自承载或规模集代理执行对 AKS 群集的访问,并可以看到群集。
- 为每个使用 Azure 资源管理器服务连接的任务创建令牌。 这可确保使用生存期较短的令牌连接到 Kubernetes,这是 Kubernetes 建议。
- 即使禁用本地帐户,也可以访问 AKS。
服务连接常见问题解答
我收到以下错误消息:找不到与服务帐户关联的任何机密。 发生了什么事情?
将 Kubernetes 服务连接与 Azure 订阅选项配合使用。 我们正在更新此方法以创建长期令牌。 这预计将在5月中旬推出。 但是,建议根据 Kubernetes 指南开始使用 Azure 服务连接类型,而不是使用长期令牌。
我使用的是 AKS,不想更改任何内容,是否可以继续将任务用于 Kubernetes 服务连接?
我们正在更新此方法以创建长期令牌。 这预计将在5月中旬推出。 但是,请注意,此方法针对 Kubernetes 指南。
我使用的是 Kubernetes 任务和 Kubernetes 服务连接,但未使用 AKS。 我应该担心吗?
任务将继续像以前一样工作。
是否删除 Kubernetes 服务连接类型?
无论 Kubernetes 任务在何处运行,我们的 Kubernetes 任务都适用于任何 Kubernetes 群集。 Kubernetes 服务连接将继续存在。
我是 AKS 客户,一切都运行正常,我应该采取行动吗?
无需更改任何内容。 如果在创建期间使用 Kubernetes 服务连接并选择了 Azure 订阅,则应注意有关使用长期令牌 的Kubernetes 指南。
我正在创建 Kubernetes 环境,不能选择使用服务连接
如果在创建环境期间无法访问 AKS,则可以使用空环境并将 connectionType
输入设置为 Azure 资源管理器服务连接。
我配置了 Azure Active Directory RBAC 的 AKS,管道不起作用。 这些更新会解决此问题吗?
启用 AAD RBAC 时访问 Kubernetes 与创建令牌无关。 为了防止交互式提示,我们将在将来的更新中支持 kubelogin。
命令
命令输入接受 kubectl 命令。
此 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 示例演示如何将配置文件与 应用 命令配合使用:
- 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 示例基于为 secretArguments 输入指定的文本值创建泛型机密:
- 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
ConfigMaps 允许将配置项目与映像内容分离,以保持容器化应用程序的可移植性。
此 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 范围