-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8s-cp: generate admin kubeconfig real good
- Loading branch information
Showing
4 changed files
with
132 additions
and
51 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
charts/k8s-control-plane/files/admin-kubeconfig-generator.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
template: | ||
spec: | ||
containers: | ||
- name: admin-kubeconfig-generator | ||
image: bitnami/kubectl:{{ $.Values.version }} | ||
command: | ||
- bash | ||
- -uexo | ||
- pipefail | ||
- -c | ||
- | | ||
kubectl create secret generic admin-kubeconfig-external --from-file=value=<(KUBECONFIG=/kubeconfig-external kubectl config view --flatten --raw) --dry-run=client --output yaml \ | ||
| kubectl apply -f- | ||
kubectl create secret generic admin-kubeconfig --from-file=value=<(KUBECONFIG=/kubeconfig kubectl config view --flatten --raw) --dry-run=client --output yaml \ | ||
| kubectl apply -f- | ||
volumeMounts: | ||
- name: cert | ||
mountPath: /cert | ||
- name: kubeconfig | ||
mountPath: /kubeconfig | ||
subPath: kubeconfig | ||
- name: kubeconfig-external | ||
mountPath: /kubeconfig-external | ||
subPath: kubeconfig | ||
serviceAccount: admin-kubeconfig-generator | ||
volumes: | ||
- name: cert | ||
secret: | ||
secretName: admin | ||
- name: kubeconfig | ||
configMap: | ||
name: kubeconfig | ||
- name: kubeconfig-external | ||
configMap: | ||
name: kubeconfig-external | ||
restartPolicy: OnFailure | ||
ttlSecondsAfterFinished: 60 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,47 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
{{- $jobSpec := fromYaml (tpl ($.Files.Get "files/admin-kubeconfig-generator.yaml") $) -}} | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: admin | ||
name: admin-kubeconfig-generator | ||
spec: | ||
commonName: kubernetes-admin | ||
duration: 336h # 2 weeks | ||
issuerRef: | ||
name: ca | ||
kind: Issuer | ||
secretName: admin | ||
subject: | ||
organizations: [system:masters] | ||
usages: [client auth] | ||
schedule: "@weekly" | ||
jobTemplate: | ||
spec: | ||
{{- toYaml $jobSpec | nindent 6 }} | ||
--- | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: admin-kubeconfig-generator | ||
spec: | ||
{{- toYaml $jobSpec | nindent 2 }} | ||
--- | ||
{{- $cert := (lookup "v1" "Secret" $.Release.Namespace "admin") -}} | ||
apiVersion: v1 | ||
kind: Secret | ||
kind: ServiceAccount | ||
metadata: | ||
name: admin-kubeconfig-generator | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: admin-kubeconfig-generator | ||
rules: | ||
- apiGroups: [""] | ||
resources: [secrets] | ||
verbs: [create] | ||
- apiGroups: [""] | ||
resourceNames: [admin-kubeconfig, admin-kubeconfig-external] | ||
resources: [secrets] | ||
verbs: [get, update, patch] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: admin-kubeconfig | ||
annotations: | ||
helm.sh/hook: post-install,post-upgrade | ||
stringData: | ||
kubeconfig: | | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
certificate-authority-data: {{ get ($cert.data) "ca.crt" }} | ||
server: https://{{ $.Values.externalHostname }}:6443 | ||
name: {{ $.Values.clusterName }} | ||
contexts: | ||
- context: | ||
cluster: {{ $.Values.clusterName }} | ||
user: {{ $.Values.clusterName }}-admin | ||
name: {{ $.Values.clusterName }}-admin@{{ $.Values.clusterName }} | ||
current-context: {{ $.Values.clusterName }}-admin@{{ $.Values.clusterName }} | ||
kind: Config | ||
preferences: {} | ||
users: | ||
- name: {{ $.Values.clusterName }}-admin | ||
user: | ||
client-certificate-data: {{ get ($cert.data) "tls.crt" }} | ||
client-key-data: {{ get ($cert.data) "tls.key" }} | ||
name: admin-kubeconfig-generator | ||
subjects: | ||
- kind: ServiceAccount | ||
name: admin-kubeconfig-generator | ||
roleRef: | ||
kind: Role | ||
name: admin-kubeconfig-generator | ||
apiGroup: rbac.authorization.k8s.io |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: admin | ||
spec: | ||
commonName: kubernetes-admin | ||
duration: 336h # 2 weeks | ||
issuerRef: | ||
name: ca | ||
kind: Issuer | ||
secretName: admin | ||
subject: | ||
organizations: [system:masters] | ||
usages: [client auth] |
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