I would like to run kubectl
command from a pre-upgrade helm hook
, but I can't seem to any documentation on how to achieve this.
Do I have to create a docker image that contains kubectl
in order to achieve this?
or is there some way of achieving this without using a container?
I have a basic helm hook
which looks like this
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Chart.Name }}-change-pvc-hook
labels:
app: {{ .Chart.Name }}
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation
spec:
template:
metadata:
name: "{{.Release.Name}}"
labels:
app: {{ .Chart.Name }}
spec:
restartPolicy: Never
containers:
- name: pre-upgrade-change-pvc
if someone could explain how to run kubectl
on without a container or how I can achieve this, that would be great
Do I have to create a docker image that contains kubectl in order to achieve this?
Yes, you have to create it because containers usually are Lightweight and contain the most basic stuff. You can create container with kubernetes using Dockerfile.
Second option is to create own mutating webhook which will modify PVC (using patch).
Mutating admission Webhooks are invoked first, and can modify objects sent to the API server to enforce custom defaults. After all object modifications are complete, and after the incoming object is validated by the API server, validating admission webhooks are invoked and can reject requests to enforce custom policies.
This way you could modify PVC before Helm install
will create release.