Skip to content

Commit

Permalink
Initial Commit - A non-working skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
diranged committed Mar 8, 2021
0 parents commit 9264613
Show file tree
Hide file tree
Showing 21 changed files with 689 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.swp
*.swo

# Helm chart automated files
/charts/*/charts
.idea
119 changes: 119 additions & 0 deletions Helm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Pick the chart-name based the name of the directory we are in. This can be
# overriden - but it picks the "short name" of the directory.
CHART_NAME ?= $(notdir $(CURDIR))

# By default we look for a `values.local.yaml` file in the directory for the
# chart when it comes to doing local testing.
VALUES ?= values.local.yaml

# Target Namespace - this setting is _usually_ overriden.. but for testing of
# simple charts, the default NS should be fine on a local test cluster.
NAMESPACE ?= default

###############################################################################
# Construct the final VALUE_ARGS setting that is used to pass into Helm.
###############################################################################
VALUE_ARGS := --values values.yaml --values $(VALUES)

###############################################################################
# The default make target is a non-destructive call
###############################################################################
.DEFAULT_GOAL := template

###############################################################################
# Cleans up the current workspace
#
# If you set the optional CLEAN_DEPS_TARGET variable, that target will be
# called first during the cleanup process.
###############################################################################
.PHONY: clean
clean: $(CLEAN_DEPS_TARGET)
rm -rf charts

###############################################################################
# Optional local dependencies that can be installed.
#
# Example - if you need to set up a dependency before your helm chart is run
# that is specific to a local development experience, you can do it like this
###############################################################################
#
# LOCAL_DEPS_TARGET := install_my_thing
#
# install_my_thing:
# kubectl apply -f ....
#
# ...
#
# include ../Common.mk


###############################################################################
# If the $VALUES file does not exist, then we create it as an empty file. The
# developer can choose to fill it in if they wish - or not. Helm though requires
# that all files passed into the `--values` flag must exist.
###############################################################################
$(VALUES):
touch $(VALUES)

###############################################################################
# Sets up the dependencies for any subcharts in the charts/* directory
###############################################################################
.PHONY: deps
deps:
@echo Pulling dependencies in...
helm dependency update .

###############################################################################
# Wrapper command that builds an updated README.md for a particular project
###############################################################################
docs:
docker run --rm --volume "$$(pwd):/helm-docs" -u "$(id -u)" jnorwood/helm-docs:v1.4.0

###############################################################################
# Shortcut for generating a printed-out template of all the resources that
# will be created for this target. This is the most useful script for testing
# helm chart changes and getting the differences from one build to the next.
###############################################################################
.PHONY: template
template: $(VALUES) deps
helm template --debug $(VALUE_ARGS) --namespace $(NAMESPACE) $(CHART_NAME) .

###############################################################################
# If the LOCAL_DEPS_TARGET variable is set, then before we do the install we
# will call that target to do any dependency setup. Most of the time this
# shouldn't be necessary, but in some cases it is.
#
# Please document WHY you are setting this if you do.
###############################################################################
.PHONY: install
install: $(LOCAL_DEPS_TARGET) $(VALUES) deps
helm install --no-hooks $(VALUE_ARGS) --create-namespace --namespace $(NAMESPACE) $(CHART_NAME) .

###############################################################################
# Once an initial helm chart has been installed, the user should call the
# upgrade command going forward.
###############################################################################
.PHONY: upgrade
upgrade: $(VALUES) deps
helm upgrade --install $(VALUE_ARGS) --namespace $(NAMESPACE) $(CHART_NAME) .

###############################################################################
# See the status of the current Helm deployment for an app
###############################################################################
.PHONY: status
status:
helm status --namespace $(NAMESPACE) $(CHART_NAME)

###############################################################################
# List the helm charts launched in our namespace
###############################################################################
.PHONY: list
list:
helm list --namespace $(NAMESPACE)

###############################################################################
# Deleteing the charts should fully clean up your envirionment
###############################################################################
.PHONY: delete
delete:
helm delete --namespace $(NAMESPACE) $(CHART_NAME)
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Shared Private Helm Chart Components

This repo holds a series of common helm-charts that we've developed just to
help speed up our internal development and reduce repetition. These charts are
private - we do not publish them at a public endpoint, instead we use Git
Submodules to bring them into your project.

## Installation of this repo

...

## Charts

All charts are fully documented in their individual values files. Use `helm
show values charts/<chart name>` to see the documentated values for each chart.

## Using Charts in your Helm Chart

The intention of this repository is to make re-usable components - not projects
that are launched on their own. Given your existing `Chart.yaml` that looks like this:


apiVersion: v2
appVersion: "1.0"
description: Launches the Nextdoor Widget Service
name: neighbors-widget
version: 0.1.0

You can add a simple `dependencies` section to bring in a component chart, and
then configure it with your `values.yaml` files. Here's the new `Chart.yaml` for example:

apiVersion: v2
appVersion: "1.0"
description: Launches the Nextdoor Widget Service
name: neighbors-widget
version: 0.1.0
dependencies:
- name: prometheus-alerts
version: 0.0.2
repository: https://oss.nextdoor.com/k8s-public-harts

And you might then configure your `values.yaml` like this:

# My own app configs..
image: ...
tag: ...

# Customize the alerting for this project
prometheus-alerts:
alertManager:
enabled: true
pagerduty:
routing_key: ...
23 changes: 23 additions & 0 deletions charts/simple-app/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
24 changes: 24 additions & 0 deletions charts/simple-app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: simple-app
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.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
1 change: 1 addition & 0 deletions charts/simple-app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Helm.mk
22 changes: 22 additions & 0 deletions charts/simple-app/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 }}{{ .path }}
{{- 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 "simple-app.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 "simple-app.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "simple-app.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 "simple-app.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions charts/simple-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "simple-app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "simple-app.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "simple-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "simple-app.labels" -}}
helm.sh/chart: {{ include "simple-app.chart" . }}
{{ include "simple-app.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "simple-app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "simple-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "simple-app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "simple-app.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
61 changes: 61 additions & 0 deletions charts/simple-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "simple-app.fullname" . }}
labels:
{{- include "simple-app.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "simple-app.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "simple-app.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "simple-app.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
Loading

0 comments on commit 9264613

Please sign in to comment.