> For the complete CircleCI developer hub index, see [llms.txt](https://circleci.com/developer/llms.txt)

# lifeway/kubernetes

Collection of Kubernetes tools

## Commands

### setup-credentials

| Parameter | Type | Default | Description |
|---|---|---|---|
| `encoded-kubeconfig` | string |  | Base64 encoded kubeconfig file |
| `kube-context` | string |  | Context to use from kubeconfig file |

### kubectl-apply

| Parameter | Type | Default | Description |
|---|---|---|---|
| `manifest-path` | string |  | Path to Kubernetes manifest file or directory to deploy |
| `recursive` | boolean | false | Set to true to recursively deploy a directory of Kubernetes manifests |

### kubectl-rollout-status

| Parameter | Type | Default | Description |
|---|---|---|---|
| `workload-type` | enum | deployment | Type of workload. Must be one of "deployment", "daemonset", or "statefulset" |
| `workload-name` | string |  | Name of workload |
| `workload-namespace` | string |  | Namespace where workload is deployed |

### kubectl-rollout-undo

| Parameter | Type | Default | Description |
|---|---|---|---|
| `workload-type` | enum | deployment | Type of workload. Must be one of "deployment", "daemonset", or "statefulset" |
| `workload-name` | string |  | Name of workload |
| `workload-namespace` | string |  | Namespace where workload is deployed |

### write-version

| Parameter | Type | Default | Description |
|---|---|---|---|
| `version-number` | string |  | Version number to write |
| `version-placeholder` | string |  | Placeholder string to find and rewrite with version |
| `version-file` | string |  | Path to file where version will be written |

### helmfile-sync

| Parameter | Type | Default | Description |
|---|---|---|---|
| `helmfile-path` | string | ./helmfile.yaml | Path to helmfile.yaml |

## Jobs

### kubectl-deploy

| Parameter | Type | Default | Description |
|---|---|---|---|
| `kubectl-version` | string | 1.22.12 | Version of kubectl to use |
| `encoded-kubeconfig` | string |  | Base64 encoded kubeconfig file |
| `kube-context` | string |  | Context to use from kubeconfig file |
| `manifest-path` | string |  | Path to Kubernetes manifest file or directory to deploy |
| `recursive` | boolean | false | Set to true to recursively deploy a directory of Kubernetes manifests |
| `write-version` | boolean | false | Set to true to write version into file before deploying. If set to true then you must also set "version-number", "version-placeholder", and "version-file" parameters |
| `version-number` | string |  | Version number to write |
| `version-placeholder` | string |  | Placeholder to find and rewrite with version |
| `version-file` | string |  | Path to file where version will be written |
| `resource_class` | string | medium | Override the resource class used by the job |

### kubectl-validate

| Parameter | Type | Default | Description |
|---|---|---|---|
| `kubectl-version` | string | 1.22.12 | Version of kubectl to use |
| `encoded-kubeconfig` | string |  | Base64 encoded kubeconfig file |
| `kube-context` | string |  | Context to use from kubeconfig file |
| `workload-type` | enum | deployment | Type of workload. Must be one of "deployment", "daemonset", or "statefulset" |
| `workload-name` | string |  | Name of workload |
| `workload-namespace` | string |  | Namespace where workload is deployed |
| `rollback` | boolean | false | Set to true to automatically rollback the workload version if validation fails (kubectl rollout undo) |
| `resource_class` | string | medium | Override the resource class used by the job |

### helmfile-deploy

| Parameter | Type | Default | Description |
|---|---|---|---|
| `helm-version` | string | 3.5.4 | Version of helm to use |
| `kube-context` | string |  | Context to use from kubeconfig file |
| `encoded-kubeconfig` | string |  | Base64 encoded kubeconfig file |
| `helmfile-path` | string | ./helmfile.yaml | Path to helmfile.yaml |
| `write-version` | boolean | false | Set to true to write version into file before deploying. If set to true then you must also set "version-number", "version-placeholder", and "version-file" parameters |
| `version-number` | string |  | Version number to write |
| `version-placeholder` | string |  | Placeholder to find and rewrite with version |
| `version-file` | string |  | Path to file where version will be written |
| `resource_class` | string | medium | Override the resource class used by the job |

### kubectl-deploy-and-validate

| Parameter | Type | Default | Description |
|---|---|---|---|
| `kubectl-version` | string | 1.22.12 | Version of kubectl to use |
| `encoded-kubeconfig` | string |  | Base64 encoded kubeconfig file |
| `kube-context` | string |  | Context to use from kubeconfig file |
| `manifest-path` | string |  | Path to Kubernetes manifest file or directory to deploy |
| `recursive` | boolean | false | Set to true to recursively deploy a directory of Kubernetes manifests |
| `write-version` | boolean | false | Set to true to write version into file before deploying. If set to true then you must also set "version-number", "version-placeholder", and "version-file" parameters |
| `version-number` | string |  | Version number to write |
| `version-placeholder` | string |  | Placeholder to find and rewrite with version |
| `version-file` | string |  | Path to file where version will be written |
| `workload-type` | enum | deployment | Type of workload. Must be one of "deployment", "daemonset", or "statefulset" |
| `workload-name` | string |  | Name of workload |
| `workload-namespace` | string |  | Namespace where workload is deployed |
| `rollback` | boolean | false | Set to true to automatically rollback the workload version if validation fails (kubectl rollout undo) |
| `slack-send-status` | boolean | false | Set to true to send build status to Slack |
| `slack-fail-only` | boolean | false | Set to true to only send build status to Slack if job is failing |
| `slack-webhook` | string |  | Slack webhook to send status to |
| `resource_class` | string | medium | Override the resource class used by the job |

## Executors

### kubectl

| Parameter | Type | Default | Description |
|---|---|---|---|
| `version` | string | 1.22.12 | kubectl version |
| `resource_class` | string | medium |  |

### helm

| Parameter | Type | Default | Description |
|---|---|---|---|
| `version` | string | 3.5.4 | helm version |
| `resource_class` | string | medium |  |

## Examples

### kubectl-deploy

Setup credentials then run 'kubectl apply'

```yaml
version: 2.1
orbs:
  kubernetes: lifeway/kubernetes@2
workflows:
  deploy:
    jobs:
      - kubernetes/kubectl-deploy:
          name: nonprod
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: nonprod-k8s-cluster
          manifest-path: nonprod
          recursive: true
      - kubernetes/kubectl-deploy:
          name: prod
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: prod-k8s-cluster
          manifest-path: prod
          recursive: true
```

### kubectl-validate

Validate that a workload is rolled out successfully

```yaml
version: 2.1
orbs:
  kubernetes: lifeway/kubernetes@2
workflows:
  deploy:
    jobs:
      - kubernetes/kubectl-validate:
          name: nonprod-validate
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: nonprod-k8s-cluster
          workload-name: my-app
          workload-namespace: my-namespace
          rollback: true
      - kubernetes/kubectl-validate:
          name: prod-validate
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: prod-k8s-cluster
          workload-name: my-app
          workload-namespace: my-namespace
          rollback: true
```

### helmfile-deploy

Setup credentials then run 'helmfile sync'

```yaml
version: 2.1
orbs:
  kubernetes: lifeway/kubernetes@2
workflows:
  deploy:
    jobs:
      - kubernetes/helmfile-deploy:
          name: nonprod
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: nonprod-k8s-cluster
          helmfile-path: nonprod/helmfile.yaml
      - kubernetes/helmfile-deploy:
          name: prod
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: prod-k8s-cluster
          helmfile-path: prod/helmfile.yaml
```

### kubectl-deploy-and-validate

Deploy a workload and then validate that it is rolled out successfully

```yaml
version: 2.1
orbs:
  kubernetes: lifeway/kubernetes@2
workflows:
  deploy:
    jobs:
      - kubernetes/kubectl-deploy-and-validate:
          name: nonprod
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: nonprod-k8s-cluster
          manifest-path: nonprod
          recursive: true
          write-version: true
          version-number: ${CIRCLE_SHA1}
          version-placeholder: '{IMAGE_PLACEHOLDER}'
          version-file: nonprod/deploy.yaml
          workload-name: my-app
          workload-namespace: my-namespace
          rollback: true
      - kubernetes/kubectl-deploy-and-validate:
          name: prod
          encoded-kubeconfig: ${KUBECONFIG_ENCODED}
          kube-context: prod-k8s-cluster
          manifest-path: prod
          recursive: true
          write-version: true
          version-number: ${CIRCLE_SHA1}
          version-placeholder: '{IMAGE_PLACEHOLDER}'
          version-file: prod/deploy.yaml
          workload-name: my-app
          workload-namespace: my-namespace
          rollback: true
```