Last active
July 24, 2024 18:12
-
-
Save x95castle1/8ed9345e5f2b75ef6f1c0372b0d29fb7 to your computer and use it in GitHub Desktop.
Gist to add HPA and PDB to Carvel Packages produced by TAP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@data/values | |
--- | |
workload_name: jeremy | |
hpa: | |
enabled: true | |
minReplicas: 5 | |
maxReplicas: 10 | |
metrics: | |
- type: Resource | |
resource: | |
name: cpu | |
target: | |
type: Utilization | |
averageUtilization: 10 | |
- type: Pods | |
pods: | |
metric: | |
name: packets-per-second | |
target: | |
type: AverageValue | |
averageValue: 1k | |
pdb: | |
enabled: true | |
minAvailable: 50% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ load("@ytt:data", "data") | |
#@ if hasattr(data.values, "pdb") and hasattr(data.values.pdb, "enabled") and data.values.pdb.enabled == True: | |
--- | |
apiVersion: policy/v1 | |
kind: PodDisruptionBudget | |
metadata: | |
name: #@ data.values.workload_name + "-pdb" | |
spec: | |
minAvailable: #@ data.values.pdb.minAvailable | |
selector: | |
matchLabels: | |
app: #@ data.values.workload_name | |
#@ end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ load("@ytt:data", "data") | |
#@ if hasattr(data.values, "hpa") and hasattr(data.values.hpa, "enabled") and data.values.hpa.enabled == True: | |
--- | |
apiVersion: kapp.k14s.io/v1alpha1 | |
kind: Config | |
rebaseRules: | |
- path: [spec, replicas] | |
type: copy | |
sources: [existing, new] | |
resourceMatchers: | |
- apiGroupKindMatcher: {apiGroup: apps, kind: Deployment} | |
--- | |
apiVersion: autoscaling/v2 | |
kind: HorizontalPodAutoscaler | |
metadata: | |
name: #@ data.values.workload_name | |
spec: | |
scaleTargetRef: | |
apiVersion: apps/v1 | |
kind: Deployment | |
name: #@ data.values.workload_name | |
minReplicas: #@ data.values.hpa.minReplicas | |
maxReplicas: #@ data.values.hpa.maxReplicas | |
metrics: #@ data.values.hpa.metrics | |
#@ end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@data/values-schema | |
--- | |
#@schema/title "Workload name" | |
#@schema/example "tanzu-java-web-app" | |
#@schema/validation min_len=1 | |
workload_name: "" | |
#@schema/title "Pod Disruption Budget" | |
#@schema/description "https://kubernetes.io/docs/tasks/run-application/configure-pdb/" | |
#@schema/nullable | |
pdb: | |
#@schema/title "minAvailable" | |
#@schema/description "the number of pods from that set that must still be available after the eviction, even in the absence of the evicted pod. minAvailable can be either an absolute number or a percentage. Default is 60%" | |
#@schema/type any=True | |
minAvailable: 60% | |
#@schema/title "enabled" | |
#@schema/description "Enabled PDB to be created if set to true. Default is false." | |
enabled: false | |
#@schema/title "Horizontal Pod Autoscaler" | |
#@schema/description "https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/" | |
#@schema/nullable | |
hpa: | |
#@schema/title "minAvailable" | |
#@schema/description "minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down. Default is 1" | |
minReplicas: 1 | |
#@schema/title "maxAvailable" | |
#@schema/description "maxReplicas is the upper limit for the number of replicas to which the autoscaler can scale up. It cannot be less that minReplicas. Default is 5" | |
maxReplicas: 5 | |
#@schema/title "enabled" | |
#@schema/description "Enabled HPA to be created if set to true. Default is false. Default is false." | |
enabled: false | |
#@schema/title "enabled" | |
#@schema/description "metrics contains the specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used). Defaults to CPU at 80% utilization." | |
#@schema/type any=True | |
metrics: | |
- type: Resource | |
resource: | |
name: cpu | |
target: | |
type: Utilization | |
averageUtilization: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRole | |
metadata: | |
name: pod-disruption-budgets | |
labels: | |
apps.tanzu.vmware.com/aggregate-to-deliverable: "true" | |
rules: | |
- apiGroups: ["policy"] | |
resources: ["poddisruptionbudgets"] | |
verbs: | |
- get | |
- list | |
- watch | |
- create | |
- patch | |
- update | |
- delete | |
- deletecollection | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRole | |
metadata: | |
name: horizontal-pod-autoscalers | |
labels: | |
apps.tanzu.vmware.com/aggregate-to-deliverable: "true" | |
rules: | |
- apiGroups: ["autoscaling"] | |
resources: ["horizontalpodautoscalers"] | |
verbs: | |
- get | |
- list | |
- watch | |
- create | |
- patch | |
- update | |
- delete | |
- deletecollection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment