# Kubernetes Apply Deployment

Apply Kubernetes manifests to a cluster using kubectl apply.

## YAML Parameters

```typescript
interface YAMLParameters {
  /** Path to the Kubernetes manifest files. */
  config_path: string;
  type: "KUBERNETES_APPLY";
  /** Unique identifier for the action within the pipeline. */
  action: string;
  /** Record current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists */
  record_arg?: "TRUE" | "FALSE" | "NOT_SET";
  /** If `true`, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. */
  save_config_arg?: boolean;
  /** Automatically resolve conflicts between the modified and live configuration by using values from the modified configuration. */
  overwrite_arg?: boolean;
  /** Only relevant during a prune or a force apply. If `true`, cascade the deletion of the resources managed by pruned or deleted resources (e.g. Pods created by a ReplicationController). */
  cascade_arg?: boolean;
  /** Defines cascade deletion behavior for resources */
  cascade?: "BACKGROUND" | "ORPHAN" | "FOREGROUND";
  /** Defines whether to select all the specified resources. */
  all_arg?: boolean;
  /** Only relevant during a prune or a force apply. Period of time in seconds given to pruned or deleted resources to terminate gracefully. Ignored if negative. */
  grace_period_arg?: number;
  /** Automatically delete resource objects that do not appear in the configs and are created by either apply or create --save-config. Should be used with either -l or --all. */
  prune_arg?: boolean;
  /** Overwrite the default whitelist with `<group/version/kind>` for --prune. */
  prune_whitelist_arg?: string;
  /** Delete and re-create the specified resource, when PATCH encounters conflict and has retried for 5 times. */
  force_arg?: boolean;
  /** Validates the configuration before applying */
  validate?: boolean;
  /** Version of kubectl to use. */
  kubectl_version?: string;
  /** Target Kubernetes clusters for deployment. */
  targets?: object[];
  /** Specifies when the action should be executed. */
  trigger_time?: "ON_EVERY_EXECUTION" | "ON_SUCCESS" | "ON_FAILURE" | "ON_BACK_TO_SUCCESS" | "ON_WARNING" | "ON_WAIT_FOR_APPROVE" | "ON_TERMINATE";
  /** The list of variables for dynamic action execution. The action runs once for each value. */
  loop?: string[];
  /** Defines whether the action should be executed on each failure. Restricted to and required if the trigger_time is ON_FAILURE. */
  run_only_on_first_failure?: boolean;
  /** When set to true the action is disabled. By default it is set to false. */
  disabled?: boolean;
  /** The timeout in seconds. */
  timeout?: number;
  /** If set to true the execution will proceed, mark action as a warning and jump to the next action. Doesn't apply to deployment actions. */
  ignore_errors?: boolean;
  /** Delay time between auto retries in seconds. */
  retry_interval?: number;
  /** Number of retries if the action fails. */
  retry_count?: number;
  /** Defines whether the action should run in parallel with the next one. */
  run_next?: "WAIT_ON_SUCCESS" | "IN_SOFT_PARALLEL" | "IN_HARD_PARALLEL";
  /** The list of trigger conditions to meet so that the action can be triggered. */
  trigger_conditions?: TriggerConditionYaml[];
  /** The list of variables you can use in the action. */
  variables?: VariableYaml[];
}
```

## Type Definitions

```typescript
interface TriggerConditionYaml {
  /** The type of trigger condition */
  trigger_condition: "ALWAYS" | "ON_CHANGE" | "ON_CHANGE_AT_PATH" | "VAR_IS" | "VAR_IS_NOT" | "VAR_CONTAINS" | "VAR_NOT_CONTAINS" | "DATETIME" | "SUCCESS_PIPELINE" | "DAY" | "HOUR" | "OR" | "VAR_LESS_THAN" | "VAR_LESS_THAN_OR_EQUAL" | "VAR_GREATER_THAN" | "VAR_GREATER_THAN_OR_EQUAL" | "ACTION_STATUS_IS" | "ACTION_STATUS_IS_NOT" | "TRIGGERING_USER_IS" | "TRIGGERING_USER_IS_NOT" | "TRIGGERING_USER_IS_IN_GROUP" | "TRIGGERING_USER_IS_NOT_IN_GROUP";
  /** The value to compare the trigger variable against */
  trigger_variable_value?: string;
  /** The name of the variable to check in the trigger condition */
  trigger_variable_key?: string;
  /** The timezone for datetime trigger conditions (e.g., 'UTC', 'Europe/Warsaw') */
  timezone?: string;
  /** The hours when the datetime trigger should activate (0-23) */
  trigger_hours?: number[];
  /** The days when the datetime trigger should activate (1-7, where 1 is Monday) */
  trigger_days?: number[];
  /** The project name for cross-project pipeline triggers */
  project?: string;
  /** The pipeline name for cross-pipeline triggers */
  pipeline?: string;
  /** The email of the user who can trigger the pipeline */
  trigger_user?: string;
  /** The name of the group that can trigger the pipeline */
  trigger_group?: string;
  /** The file paths that must change to trigger the pipeline */
  trigger_condition_paths?: string[];
  /** The action status to check for action status triggers */
  trigger_status?: "SUCCESSFUL" | "FAILED" | "SKIPPED" | "SUPPRESSED";
  /** The name of the action to check status for */
  trigger_action_name?: string;
  /** The list of nested trigger conditions for OR/AND operators */
  trigger_operands?: TriggerConditionYaml[];
}

interface VariableYaml {
  /** The name of the variable */
  key: string;
  /** The value of the variable */
  value?: string;
  /** The type of the added variable */
  type?: "VAR" | "FILE" | "SSH_KEY" | "IOS_KEYCHAIN" | "IOS_PROVISION_PROFILES" | "SSH_PUBLIC_KEY" | "GPG_KEY";
  /** If set to true the variable value will be encrypted and hidden */
  encrypted?: boolean;
  /** The optional description of the variable */
  description?: string;
  /** Initial path for the variable */
  init_path?: string;
  /** Default value for the variable */
  defaults?: string;
  /** Set if type is FILE, SSH_KEY, IOS_KEYCHAIN, or IOS_PROVISION_PROFILES. If it's NONE, the variable can be used as a parameter in an action. For CONTAINER, the given key is additionally copied to an action container on each run */
  file_place?: "NONE" | "CONTAINER";
  /** Whether the file is binary */
  binary?: boolean;
  /** Public value for SSH key type variables */
  public_value?: string;
  /** Fingerprint of SSH key */
  key_fingerprint?: string;
  /** Checksum of the variable value */
  checksum?: string;
  /** Password for certificates */
  password?: string;
  /** Passphrase for encrypted SSH keys */
  passphrase?: string;
  /** Key identifier for iOS certificates, provisioning profiles, or GPG keys */
  key_identifier?: string;
  /** If set to true the variable value can be set by Buddy actions */
  settable?: string;
  /** Encoding of the variable value. Use `b64` for binary files (certificates, images, compiled blobs) where the value is already base64-encoded. Omit or set to `text` for plain text files (JSON, XML, config) — the system will handle encoding automatically. Only applies to non-encrypted asset variables (FILE, SSH_KEY, SSH_PUBLIC_KEY, IOS_KEYCHAIN, IOS_PROVISION_PROFILES). */
  encoding?: "text" | "b64";
  /** Specifies where to copy the file on each run. Set if type is FILE, SSH_KEY, IOS_KEYCHAIN, or IOS_PROVISION_PROFILES. */
  path?: string;
  /** File permission set on copy to a container on each run. Set if type is FILE, SSH_KEY, IOS_KEYCHAIN, or IOS_PROVISION_PROFILES. */
  chmod?: string;
}

```

## YAML Examples

### Deploy to Google Kubernetes Engine

```yaml
  - action: "Kubernetes - deployment apply"
    type: "KUBERNETES_APPLY"
    config_path: "config.yaml"
    validate: true
    record_arg: "NOT_SET"
    overwrite_arg: true
    cascade_arg: true
    grace_period_arg: 1
    targets:
      - target: my_gke_cluster
        type: GKE
        name: My GKE Cluster
        integration: my_integration
        cluster: cluster-1
        project: tokyo-house-138923
        zone: europe-west1-c

```

### Deploy to self-managed Kubernetes cluster

```yaml
  - action: "Apply Deployment"
    type: "KUBERNETES_APPLY"
    config_path: config.yml
    cascade_arg: true
    grace_period_arg: 180
    kubectl_version: v1.19.0
    targets:
      - target: my_target_id
        auth:
        token: 'test-token'
        method: TOKEN
      name: my-target
      type: K8S_CLUSTER
      cluster: https://192.168.5.226:6443

```

### Deploy to Amazon EKS cluster

```yaml
  - action: "Apply Deployment"
    type: "KUBERNETES_APPLY"
    config_path: "config.yaml"
    cascade_arg: true
    grace_period_arg: 0
    kubectl_version: "1.11.1"
    targets:
      - target: my_eks_cluster
        type: EKS
        name: My EKS Cluster
        integration: my_integration
        cluster: cluster-1
        region: us-west-2
        role_arn: arn:aws:iam::344123456789:role/EKS_TESTS

```

### Deploy to Azure AKS cluster

```yaml
  - action: "Apply Deployment"
    type: "KUBERNETES_APPLY"
    config_path: "config.yaml"
    cascade_arg: true
    grace_period_arg: 0
    kubectl_version: "1.11.1"
    targets:
      - target: my_aks_cluster
        type: AKS
        name: My AKS Cluster
        integration: my_integration
        cluster: buddy-tests
        subscription: d4fd0732-1b7f-47ff-8ca9-8b003428dcd8
        resource_group: test-buddy_group

```

### Deploy to DigitalOcean Kubernetes cluster

```yaml
  - action: "Apply Deployment"
    type: "KUBERNETES_APPLY"
    config_path: "config.yaml"
    cascade_arg: true
    grace_period_arg: 0
    kubectl_version: "1.11.1"
    targets:
      - target: my_doks_cluster
        type: DOKS
        name: My DOKS Cluster
        integration: my_integration
        cluster: 0ec55079-0398-4cfc-9b51-97e07cb07ae7

```


---
Original source: https://buddy.works/docs/yaml/yaml-actions/kubernetes-apply