From a57a1f7e099742d6470fa07bab22397b4c59568f Mon Sep 17 00:00:00 2001 From: Chi-En Wu Date: Mon, 27 Apr 2020 11:46:24 +0800 Subject: [PATCH] feat: add starter --- starter/.helmignore | 23 ++++++ starter/Chart.yaml | 28 +++++++ starter/templates/NOTES.txt | 21 ++++++ starter/templates/deployment.yaml | 26 +++++++ starter/templates/ingress.yaml | 3 + starter/templates/service.yaml | 3 + starter/templates/serviceaccount.yaml | 3 + starter/templates/tests/test-connection.yaml | 15 ++++ starter/values.yaml | 79 ++++++++++++++++++++ 9 files changed, 201 insertions(+) create mode 100644 starter/.helmignore create mode 100644 starter/Chart.yaml create mode 100644 starter/templates/NOTES.txt create mode 100644 starter/templates/deployment.yaml create mode 100644 starter/templates/ingress.yaml create mode 100644 starter/templates/service.yaml create mode 100644 starter/templates/serviceaccount.yaml create mode 100644 starter/templates/tests/test-connection.yaml create mode 100644 starter/values.yaml diff --git a/starter/.helmignore b/starter/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/starter/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/starter/Chart.yaml b/starter/Chart.yaml new file mode 100644 index 0000000..9e25321 --- /dev/null +++ b/starter/Chart.yaml @@ -0,0 +1,28 @@ +apiVersion: v2 +name: +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: 1.16.0 + +dependencies: +- name: common + version: "0.3.0" + repository: "https://hahow-helm-charts.storage.googleapis.com/" diff --git a/starter/templates/NOTES.txt b/starter/templates/NOTES.txt new file mode 100644 index 0000000..28adba6 --- /dev/null +++ b/starter/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "common.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "common.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/starter/templates/deployment.yaml b/starter/templates/deployment.yaml new file mode 100644 index 0000000..031199e --- /dev/null +++ b/starter/templates/deployment.yaml @@ -0,0 +1,26 @@ +{{/* vim: set filetype=mustache: */}} + +{{- include "common.deployment" (list . .Values .Values.autoscaling .Values.serviceAccount ".deployment") }} + +{{- define ".deployment" -}} +spec: + template: + spec: + containers: + - {{- include "common.container" (append . ".container") | nindent 8 }} +{{- end }} + +{{- define ".container" -}} +ports: + - name: http + containerPort: 80 + protocol: TCP +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http +{{- end }} diff --git a/starter/templates/ingress.yaml b/starter/templates/ingress.yaml new file mode 100644 index 0000000..9ef603f --- /dev/null +++ b/starter/templates/ingress.yaml @@ -0,0 +1,3 @@ +{{/* vim: set filetype=mustache: */}} + +{{- include "common.ingress" (list . .Values.ingress .Values.service) }} diff --git a/starter/templates/service.yaml b/starter/templates/service.yaml new file mode 100644 index 0000000..1c98585 --- /dev/null +++ b/starter/templates/service.yaml @@ -0,0 +1,3 @@ +{{/* vim: set filetype=mustache: */}} + +{{- include "common.service" (list . .Values.service) }} diff --git a/starter/templates/serviceaccount.yaml b/starter/templates/serviceaccount.yaml new file mode 100644 index 0000000..fbf3410 --- /dev/null +++ b/starter/templates/serviceaccount.yaml @@ -0,0 +1,3 @@ +{{/* vim: set filetype=mustache: */}} + +{{- include "common.serviceAccount" (list . .Values.serviceAccount) }} diff --git a/starter/templates/tests/test-connection.yaml b/starter/templates/tests/test-connection.yaml new file mode 100644 index 0000000..cb5e8d4 --- /dev/null +++ b/starter/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "common.fullname" . }}-test-connection" + labels: + {{- include "common.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "common.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/starter/values.yaml b/starter/values.yaml new file mode 100644 index 0000000..126ee0e --- /dev/null +++ b/starter/values.yaml @@ -0,0 +1,79 @@ +# Default values for . +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {}