Skip to content

Taskfile.kubectl

FieldValue
TypeSkill Resource
Source~/.copilot/skills/go-task/templates/Taskfile.kubectl.yml
DescriptionNot specified

Source Content

version: '3'
# =============================================================================
# Kubernetes task group. Included by the root Taskfile under the `k8s:`
# namespace, so commands are called as:
#
# task k8s:context
# task k8s:pods
# task k8s:logs DEPLOYMENT=api -- -f
# task k8s:crds install/upgrade CRDs (run BEFORE any Helm release)
# task k8s:apply apply the plain manifests under k8s/
#
# Splitting kubectl out keeps the root Taskfile readable. Mirror this file for
# other tool families (Taskfile.docker.yml, Taskfile.db.yml).
# =============================================================================
vars:
# Override per call: `task k8s:pods NAMESPACE=staging`.
NAMESPACE: '{{.NAMESPACE | default "default"}}'
# Directory holding CustomResourceDefinition manifests (see k8s:crds below).
CRD_DIR: '{{.CRD_DIR | default "k8s/crds"}}'
tasks:
context:
desc: Show the current cluster context and namespace
cmds:
- kubectl config current-context
- kubectl config view --minify --output 'jsonpath={..namespace}'
pods:
desc: List pods in the namespace
cmds:
- kubectl get pods -n {{.NAMESPACE}}
logs:
desc: Tail logs for a deployment (extra flags pass through after --)
requires:
vars: [DEPLOYMENT]
cmds:
- kubectl logs -n {{.NAMESPACE}} deploy/{{.DEPLOYMENT}} {{.CLI_ARGS}}
# --- CRDs: the kubectl step that must precede every Helm release ------------
# dmwd-io rule (pairs with the `helm` skill): CRDs are installed as a separate
# `kubectl apply` task, NEVER as Helm-managed resources. Do not rely on Helm
# CRD hooks, installCRDs, crds.enabled, or app-of-apps sync to own CRD
# lifecycle. Run `task k8s:crds` first; only then install/upgrade the Helm
# release that depends on those CRDs. See the helm skill for the chart side.
crds:
desc: Apply CustomResourceDefinitions — run BEFORE any Helm install/upgrade (see helm skill)
preconditions:
- sh: test -d {{.CRD_DIR}}
msg: 'no CRD directory at {{.CRD_DIR}} (override with CRD_DIR=...)'
cmds:
# --server-side handles the large CRD schemas Helm cannot template safely.
- kubectl apply --server-side -f {{.CRD_DIR}}
# Block until the API server has registered them, so the Helm step that
# follows can create custom resources without a race.
- kubectl wait --for condition=established --timeout=60s -f {{.CRD_DIR}}
apply:
desc: Apply the plain (non-CRD) manifests under the k8s directory
preconditions:
- sh: test -d k8s
msg: no k8s/ directory found in this project
cmds:
- kubectl apply -n {{.NAMESPACE}} -f k8s/