| name | kubernetes-deployment |
| description | Deep knowledge about deploying applications to Kubernetes clusters using kubectl, helm, and manifests. |
| type | transform |
| tier | library |
| domain | deploy |
| trigger | when deploying to Kubernetes |
Context
Deploying {{project_name}} ({{project_type}}) to Kubernetes.
You will follow a strict 6-phase Deployment Lifecycle Contract.
Instructions
Execute the following phases in order:
Phase 1: Authentication
- Ensure the
KUBECONFIG environment variable is set to a valid configuration file, or the configuration is located in ~/.kube/config.
- Authenticate to the cluster (if using cloud providers like AWS EKS or GCP GKE, use their respective commands:
aws eks update-kubeconfig or gcloud container clusters get-credentials).
- Verify access by running
kubectl cluster-info and kubectl get nodes.
Phase 2: Build
- Prepare the artifacts for deployment.
- Build your Docker image:
docker build -t <registry>/<image-name>:<tag> .
- Push the image to your container registry (DockerHub, GHCR, ECR, GCR):
docker push <registry>/<image-name>:<tag>
Phase 3: Install / Provisioning
- Ensure the target Kubernetes namespace exists:
kubectl create namespace <namespace> (if it doesn't exist).
- Create or update necessary ConfigMaps and Secrets:
kubectl apply -f k8s/configmap.yaml or use kubectl create secret generic.
- If using Helm, ensure the Helm chart dependencies are updated:
helm dependency update <chart-dir>.
Phase 4: Deploy
- Ship the artifact to Kubernetes.
- Using raw manifests: Update the image tag in your Deployment YAML, then run
kubectl apply -f k8s/.
- Using Kustomize:
kustomize build k8s/ | kubectl apply -f -.
- Using Helm:
helm upgrade --install <release-name> <chart-dir> --namespace <namespace> --set image.tag=<tag>.
Phase 5: Checking
- Verify the deployment was successful.
- Check the rollout status:
kubectl rollout status deployment/<deployment-name> -n <namespace>. This command will block until the deployment is successful or fails.
- Check pod status if there are issues:
kubectl get pods -n <namespace>.
- Inspect pod logs if they are crashing:
kubectl logs -l app=<app-label> -n <namespace>.
- Curl the service or ingress URL if available externally.
Phase 6: Update / Rollback
- If Phase 5 fails (e.g., rollout gets stuck or pods crashloop), immediately initiate a rollback.
- Using kubectl:
kubectl rollout undo deployment/<deployment-name> -n <namespace>.
- Using Helm:
helm rollback <release-name> -n <namespace>.
- Note the failure in the progress log.
Validation