Skip to content

Instantly share code, notes, and snippets.

@bgrant0607
Created June 14, 2022 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrant0607/454b9fadbf53f2a59c94c4feadbcbede to your computer and use it in GitHub Desktop.
Save bgrant0607/454b9fadbf53f2a59c94c4feadbcbede to your computer and use it in GitHub Desktop.
Simple namespace blueprint by creating a helm chart from scratch
Create simplens-chart repo
git clone https://github.com/<user>/simplens-chart
cd simplens-chart
helm create scratch-chart
find scratch-chart -print
That assumed I wanted to run an application on Kubernetes. None of it is relevant.
mkdir simplens simplens/templates
rm -rf scratch-chart
Create the following files:
Chart.yaml:
apiVersion: v2
name: simplens
description: Simple Namespace blueprint
type: application
version: 0.1.0
appVersion: “1”
templates/namespaces.yaml:
{{- range .Values.namespaces }}
---
apiVersion: v1
kind: Namespace
metadata:
name: {{ .name }}
{{- if .labels }}
labels:
{{- range $key, $value := .labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- if .annotations }}
annotations:
{{- range $key, $value := .annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
templates/service-accounts.yaml:
{{- range .Values.namespaces }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ $.Values.serviceAccountName }}
namespace: {{ .name }}
{{- end }}
templates/role-bindings.yaml
{{- range .Values.namespaces }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $.Values.serviceAccountName }}-{{ $.Values.roleBindingRole }}
namespace: {{ .name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ $.Values.roleBindingRole }}
subjects:
- kind: ServiceAccount
name: {{ $.Values.serviceAccountName }}
namespace: {{ .name }}
{{- end }}
values.yaml:
labels:
istio-injection: enabled
annotations:
network-type: mesh
serviceAccountName: app-admin
roleBindingRole: app-admin
namespaces:
- name: backend1
- name: backend2
- name: backend3
helm template test simplens –output-dir test
Look at the output files
git add simplens
git commit
git push origin main
helm install mysetup simplens
helm uninstall mysetup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment