diff --git a/charts/rancher/custom-values.yaml b/charts/rancher/custom-values.yaml index f4621e0..553d0d8 100644 --- a/charts/rancher/custom-values.yaml +++ b/charts/rancher/custom-values.yaml @@ -13,9 +13,9 @@ ingress: nginx.ingress.kubernetes.io/proxy-body-size: 10m # cert-manager 사용시 - cert-manager.io/cluster-issuer: "selfsigned-issuer" - cert-manager.io/duration: 8760h - cert-manager.io/renew-before: 720h + # cert-manager.io/cluster-issuer: "selfsigned-issuer" + # cert-manager.io/duration: 8760h + # cert-manager.io/renew-before: 720h # 사설 인증서 사용시 true @@ -37,4 +37,6 @@ resources: extraEnv: - name: TZ - value: Asia/Seoul \ No newline at end of file + value: Asia/Seoul + +preinstallHook: true diff --git a/charts/rancher/templates/preinstallHook/certificate.yaml b/charts/rancher/templates/preinstallHook/certificate.yaml new file mode 100644 index 0000000..3ca6d0a --- /dev/null +++ b/charts/rancher/templates/preinstallHook/certificate.yaml @@ -0,0 +1,19 @@ +{{- if .Values.preinstallHook }} +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: {{ .Values.ingress.tls.secretName }} + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "1" # Certificate 생성 후 실행되도록 우선순위 설정 + "helm.sh/hook-delete-policy": before-hook-creation +spec: + secretName: {{ .Values.ingress.tls.secretName }} + duration: 8750h + renewBefore: 720h + issuerRef: + name: selfsigned-issuer + kind: ClusterIssuer + dnsNames: + - {{ .Values.hostname }} +{{- end }} diff --git a/charts/rancher/templates/preinstallHook/create-tls-ca-job.yaml b/charts/rancher/templates/preinstallHook/create-tls-ca-job.yaml new file mode 100644 index 0000000..912c4fc --- /dev/null +++ b/charts/rancher/templates/preinstallHook/create-tls-ca-job.yaml @@ -0,0 +1,31 @@ +{{- if .Values.preinstallHook }} +apiVersion: batch/v1 +kind: Job +metadata: + name: create-tls-ca-job + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "2" # Certificate 생성 후 실행되도록 우선순위 설정 + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed +spec: + backoffLimit: 4 + template: + spec: + serviceAccountName: create-tls-ca-sa + containers: + - name: create-secret + image: bitnami/kubectl:latest + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - | + echo "Waiting for rancher-tls-secret to be created..." + while [ $(kubectl get secret {{ .Values.ingress.tls.secretName }} -n {{ .Release.Namespace }} --ignore-not-found | wc -l) -lt 2 ]; do + sleep 1 + done + echo "Creating new secret with custom key..." + RANCHER_CA_CERT=$(kubectl get secret {{ .Values.ingress.tls.secretName }} -o jsonpath='{.data.ca\.crt}' -n {{ .Release.Namespace }} | base64 -d) + kubectl create secret generic tls-ca --from-literal=cacerts\.pem="${RANCHER_CA_CERT}" -n {{ .Release.Namespace }} + restartPolicy: OnFailure +{{- end }} diff --git a/charts/rancher/templates/preinstallHook/role.yaml b/charts/rancher/templates/preinstallHook/role.yaml new file mode 100644 index 0000000..228ce7e --- /dev/null +++ b/charts/rancher/templates/preinstallHook/role.yaml @@ -0,0 +1,14 @@ +{{- if .Values.preinstallHook }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: create-tls-ca-role + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-2" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed +rules: + - apiGroups: [""] + resources: ["secrets"] + verbs: ["get", "create", "update", "patch", "list"] +{{- end }} diff --git a/charts/rancher/templates/preinstallHook/rolebinding.yaml b/charts/rancher/templates/preinstallHook/rolebinding.yaml new file mode 100644 index 0000000..d090659 --- /dev/null +++ b/charts/rancher/templates/preinstallHook/rolebinding.yaml @@ -0,0 +1,17 @@ +{{- if .Values.preinstallHook }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: create-tls-ca-rolebinding + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-1" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed +subjects: + - kind: ServiceAccount + name: create-tls-ca-sa + namespace: {{ .Release.Namespace }} +roleRef: + kind: Role + name: create-tls-ca-role +{{- end }} diff --git a/charts/rancher/templates/preinstallHook/serviceaccount.yaml b/charts/rancher/templates/preinstallHook/serviceaccount.yaml new file mode 100644 index 0000000..90ae811 --- /dev/null +++ b/charts/rancher/templates/preinstallHook/serviceaccount.yaml @@ -0,0 +1,10 @@ +{{- if .Values.preinstallHook }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: create-tls-ca-sa + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-3" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed +{{- end }} diff --git a/charts/rancher/values.yaml b/charts/rancher/values.yaml index 83aeda3..1d35985 100644 --- a/charts/rancher/values.yaml +++ b/charts/rancher/values.yaml @@ -197,3 +197,5 @@ webhook: "" # helm values to use when installing the fleet chart. # helm values set here will override all other global values used when installing the fleet chart. fleet: "" + +preinstallHook: false