Post Install Actions
Table of contents
- Overview
- Supported Actions
- Configuration
- Configuration Options
- Examples
- How It Works
- Validation
- Execution Order
- Important Notes
- Troubleshooting
- Best Practices
Overview
Post-install actions allow you to perform automated operations on Kubernetes resources after the cluster setup is complete. This is useful for:
- Restarting deployments after configuration changes
- Cleaning up temporary pods
- Forcing rollouts to pick up new configurations
- Removing debug resources
Actions run after Helm charts are installed, manifests are applied, and patches are applied.
Supported Actions
restart
Performs a rollout restart on the specified resource (equivalent to kubectl rollout restart).
Supported resource kinds:
DeploymentStatefulSetDaemonSet
delete
Deletes the specified resource (equivalent to kubectl delete).
Supported resource kinds:
Pod
Configuration
Add actions under the postInstallActions key:
postInstallActions:
- action: restart
kind: Deployment
name: argocd-server
namespace: argocd
- action: delete
kind: Pod
name: old-pod
namespace: default
Configuration Options
action (Required)
Type: string
Values: restart | delete
Description: The action to perform on the resource.
action: restart
kind (Required)
Type: string
Description: The kind of Kubernetes resource.
- For
restartaction:Deployment,StatefulSet, orDaemonSet - For
deleteaction:Pod
kind: Deployment
namespace
Type: string
Optional: Yes
Default: default
Description: The namespace where the resource(s) exist.
namespace: argocd
name
Type: string
Optional: Either name or labelSelector must be provided
Description: The name of a specific resource to target.
name: argocd-server
If both name and labelSelector are provided, labelSelector takes precedence and name is ignored.
labelSelector
Type: object (map of label key-value pairs)
Optional: Either name or labelSelector must be provided
Description: Labels to select multiple resources. All resources matching the labels will be affected.
labelSelector:
app.kubernetes.io/name: argocd-server
app.kubernetes.io/component: server
group
Type: string
Optional: Yes
Description: The API group of the resource.
Defaults:
Pod: `` (empty string / core API)Deployment,StatefulSet,DaemonSet:apps
You typically don’t need to specify this unless working with custom resources.
group: apps
version
Type: string
Optional: Yes
Default: v1
Description: The API version of the resource.
version: v1
Examples
Restart by Name
Restart a specific deployment by name:
postInstallActions:
- action: restart
kind: Deployment
name: argocd-server
namespace: argocd
This is equivalent to:
kubectl rollout restart deployment/argocd-server -n argocd
Restart by Label Selector
Restart all deployments matching specific labels:
postInstallActions:
- action: restart
kind: Deployment
namespace: argocd
labelSelector:
app.kubernetes.io/name: argocd-applicationset-controller
This is equivalent to:
kubectl rollout restart deployment -n argocd -l app.kubernetes.io/name=argocd-applicationset-controller
Restart Multiple Resources
Use multiple labels to target specific resources:
postInstallActions:
- action: restart
kind: Deployment
namespace: production
labelSelector:
app: myapp
environment: production
version: v2
Restart Different Resource Types
postInstallActions:
- action: restart
kind: Deployment
name: web-app
namespace: default
- action: restart
kind: StatefulSet
name: database
namespace: default
- action: restart
kind: DaemonSet
name: monitoring-agent
namespace: monitoring
Delete by Name
Delete a specific pod:
postInstallActions:
- action: delete
kind: Pod
name: temporary-job
namespace: default
This is equivalent to:
kubectl delete pod/temporary-job -n default
Delete by Label Selector
Delete all pods matching specific labels:
postInstallActions:
- action: delete
kind: Pod
namespace: kube-system
labelSelector:
app: cleanup
temporary: "true"
This is equivalent to:
kubectl delete pod -n kube-system -l app=cleanup,temporary=true
Combined Workflow
Restart deployments and clean up temporary pods:
postInstallActions:
# Restart Argo CD components to pick up new config
- action: restart
kind: Deployment
namespace: argocd
labelSelector:
app.kubernetes.io/part-of: argocd
# Remove debug pods
- action: delete
kind: Pod
namespace: default
labelSelector:
debug: "true"
# Remove specific temporary pod
- action: delete
kind: Pod
name: init-job-xyz
namespace: default
How It Works
Restart Action
When you restart a resource, BeKind:
- Gets the resource using the Kubernetes dynamic client
- Updates the pod template annotation:
kubectl.kubernetes.io/restartedAt: "2024-11-16T10:30:00Z" - This triggers Kubernetes to perform a rolling restart
The restart is graceful and follows the resource’s update strategy.
Delete Action
When you delete a resource, BeKind:
- Finds the resource(s) matching the criteria
- Deletes each resource using the Kubernetes API
- The resource is removed immediately (subject to grace periods)
Validation
BeKind validates your configuration before executing:
Required Fields
actionmust be specifiedkindmust be specified- Either
nameorlabelSelectormust be provided
Action-Kind Compatibility
restartaction only works with:Deployment,StatefulSet,DaemonSetdeleteaction only works with:Pod
Using invalid combinations will result in an error.
Execution Order
Actions are executed in the order they appear in your configuration:
postInstallActions:
- action: restart
kind: Deployment
name: first # Executed first
- action: restart
kind: Deployment
name: second # Executed second
- action: delete
kind: Pod
name: cleanup # Executed third
Full Execution Flow
- KIND cluster is created
- Docker images are loaded (if configured)
- Helm charts are installed (if configured)
- Post-install manifests are applied (if configured)
- Post-install patches are applied (if configured)
- Post-install actions are performed ← You are here
This order allows you to patch resources first, then trigger actions like restarts to pick up the patched configurations.
Important Notes
Label Selector Precedence
If both name and labelSelector are provided, labelSelector takes precedence and name is ignored.
# This will use labelSelector and ignore name
postInstallActions:
- action: restart
kind: Deployment
name: ignored-name # This is ignored
labelSelector:
app: myapp # This is used
Core API Group
For Pods (core API resources), use an empty string for the group or omit it entirely:
# Both are correct
postInstallActions:
- action: delete
kind: Pod
group: "" # Explicit empty string
- action: delete
kind: Pod # Group omitted (uses default)
No Rollback
Actions are executed once and not tracked. There is no automatic rollback if something fails.
Troubleshooting
Resource Not Found
If you get “resource not found” errors:
- Check resource exists:
kubectl get deployment argocd-server -n argocd - Verify namespace:
kubectl get deployment --all-namespaces | grep argocd-server - Check spelling: Resource names and namespaces are case-sensitive
Label Selector Not Matching
If label selectors don’t find resources:
- Check labels on resources:
kubectl get deployment -n argocd --show-labels - Verify label syntax:
# Correct labelSelector: app.kubernetes.io/name: argocd # Wrong - values must be strings labelSelector: replicas: 1 # This won't work - Test selector manually:
kubectl get deployment -n argocd -l app.kubernetes.io/name=argocd
Action Not Supported
If you get “action not supported” errors:
-
Check action name: Must be exactly
restartordelete -
Verify kind is supported:
restart: OnlyDeployment,StatefulSet,DaemonSetdelete: OnlyPod
Permission Errors
If you get permission errors:
- Check cluster access:
kubectl auth can-i update deployments -n argocd kubectl auth can-i delete pods -n default - Verify RBAC: Ensure your kubeconfig has appropriate permissions
Best Practices
Use with Helm Charts
Restart deployments after Helm installs to pick up new configurations:
helmCharts:
- url: "https://argoproj.github.io/argo-helm"
repo: "argo"
chart: "argo-cd"
release: "argocd"
namespace: "argocd"
wait: true
postInstallActions:
- action: restart
kind: Deployment
namespace: argocd
labelSelector:
app.kubernetes.io/part-of: argocd
Clean Up After Manifests
Remove temporary resources created by manifests:
postInstallManifests:
- "file:///path/to/init-job.yaml"
postInstallActions:
- action: delete
kind: Pod
namespace: default
labelSelector:
job: init
Use Label Selectors for Flexibility
Label selectors are more flexible than names:
# Good - works even if deployment name changes
postInstallActions:
- action: restart
kind: Deployment
labelSelector:
app: myapp
# Less flexible - breaks if name changes
postInstallActions:
- action: restart
kind: Deployment
name: myapp-deployment-v1
Validate Labels First
Before using label selectors in BeKind, test them:
# Check what will be affected
kubectl get deployment -n argocd -l app.kubernetes.io/part-of=argocd
# Verify it's what you expect
kubectl get deployment -n argocd -l app.kubernetes.io/part-of=argocd -o name