helm-nginx-example
Helm chart to show basic usage with an nginx server hosting static content.
Note that this helm chart comes with a lot of extra components that may not be
needed for a bare-minimum web server application. However, it is recommended
to keep them here for the future. See the various resource definitions in
chart/helm-nginx-example/templates
to see the resources that the helm
chart will be created when a release is made.
How this was created
mkdir chart
cd chart
helm create helm-nginx-example
At the time of writing, only one small change has been made to this helm chart to reflect deprecations in newer versions of Kubernetes. These changes can be seen in this commit: 8477b491. For convenience, the changes are shown below.
--- a/chart/helm-nginx-example/templates/ingress.yaml (revision 6498dbf8231b37d521831df91af1418631b91722)
+++ b/chart/helm-nginx-example/templates/ingress.yaml (date 1620663685002)
@@ -1,11 +1,7 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "helm-nginx-example.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
-{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
-apiVersion: networking.k8s.io/v1beta1
-{{- else -}}
-apiVersion: extensions/v1beta1
-{{- end }}
+apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}
@@ -33,9 +29,12 @@
paths:
{{- range .paths }}
- path: {{ .path }}
+ pathType: Prefix
backend:
- serviceName: {{ $fullName }}
- servicePort: {{ $svcPort }}
+ service:
+ name: {{ $fullName }}
+ port:
+ number: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
Check the git history of the chart
directory for any other changes that
may have been made.
How to use this
The below instructions assume you want to install this chart from your local system to a remote kubernetes cluster.
Dependencies:
- A clone of this repository.
- Kube config context set to point to the target cluster See here for more information.
- Helm v3+ and kubectl installed on your local system.
- Existing namespace on the target cluster.
Basic Installation
# Example: helm install -n <k8s-namespace-name> release-name chart-path
helm install -n davidh-test test-nginx chart/helm-nginx-example
This should output something like:
NAME: test-nginx
LAST DEPLOYED: Mon May 10 10:46:22 2021
NAMESPACE: davidh-test
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace davidh-test -l "app.kubernetes.io/name=helm-nginx-example,app.kubernetes.io/instance=test-nginx" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace davidh-test $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace davidh-test port-forward $POD_NAME 8080:$CONTAINER_PORT
Run the specified commands and go to "http://localhost:8080" in your browser to see the nginx welcome page.
Uninstall
# Example: helm uninstall -n <k8s-namespace-name> release-name
helm uninstall -n davidh-test test-nginx
Alternate Installation - HTTPS Certificate
Dependencies:
- A TC-configured DNS entry for a specific domain. In this example we'll use "beta-geosphere2.ssec.wisc.edu".
- A default SSL certificate for the Ingress Controller on the cluster. This is typically automatically configured by TC for rancher-based clusters.
One way to do this installation is to change individual values of the helm
chart's defaults (stored in chart/helm-nginx-example/values.yaml
).
helm install -n davidh-test --set ingress.enabled=true --set ingress.hosts[0].host="beta-geosphere2.ssec.wisc.edu" --set ingress.hosts[0].paths[0].path="/" --set ingress.tls[0].hosts[0]="beta-geosphere2.ssec.wisc.edu" test-nginx chart/helm-nginx-example
Alternatively, you could store this configuration in a separate YAML file:
# my-values.yaml
ingress:
enabled: true
hosts:
- host: "beta-geosphere2.ssec.wisc.edu"
paths:
- path: "/"
tls:
- hosts:
- "beta-geosphere2.ssec.wisc.edu"
And then specify the YAML file on the command line:
helm install -n davidh-test --values my-values.yaml test-nginx chart/helm-nginx-example
Using either of these methods, you should then be able to go to your URL (ex. "https://my-url.ssec.wisc.edu") and see the nginx welcome page. If your certificates are properly set up then you shouldn't need to accept the certificate in your browser. If you do, this is a sign that you are using the wrong SSL certificate.
Other Options
See chart/helm-nginx-example/values.yaml
for other configuration options for
this default helm chart. For additional kubernetes functionality the templates
must be updated to reflect the options you would like to use.