Update "Node Deploy with Helm"

This commit is contained in:
timlackhan
2019-11-18 16:33:33 +08:00
committed by qzheng527
parent 90b81349f6
commit 0de0d4531a
9 changed files with 282 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
+5
View File
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: node
version: 0.1.0
+73
View File
@@ -0,0 +1,73 @@
# Clear Linux* OS `node` Helm Charts
<!-- Required -->
## What is this image?
`clearlinux/node` is a Docker image with `node` running on top of the [official clearlinux base image](https://hub.docker.com/_/clearlinux).
> [Node](https://nodejs.org/en/) is a JavaScript runtime built on Chrome's V8 JavaScript engine.
For other Clear Linux* OS based container images, see: https://hub.docker.com/u/clearlinux
## Why use a clearlinux based image?
> [Clear Linux* OS](https://clearlinux.org/) is an open source, rolling release Linux distribution optimized for performance and security, from the Cloud to the Edge, designed for customization, and manageability.
Clear Linux* OS based container images use:
- Optimized libraries that are compiled with latest compiler versions and flags.
- Software packages that follow upstream source closely and update frequently.
- An aggressive security model and best practices for CVE patching.
- A multi-staged build approach to keep a reduced container image size.
- The same container syntax as the official images to make getting started easy.
To learn more about Clear Linux* OS, visit: [https://clearlinux.org](https://clearlinux.org/).
<!-- Required -->
## Installing the Node Chart
Download the node chart and install the chart with the release name ` my-release`
```
$ helm install --name my-release node
```
## Uninstalling the Chart
To uninstall/delete the `my-release` deployment:
```
$ helm delete my-release
```
The command removes all the Kubernetes components associated with the chart and deletes the release.
## Parameters
The following table lists the configurable parameters of the node chart and their default values.
| Parameter | Description | Default |
| ------------------------------ | ------------------------------------------- | --------------------------- |
| `image.replicaCount` | node pod count | `2` |
| `image.repository` | node image repository | `docker.io/clearlinux/node` |
| `image.imagepullPolicy` | node image pull policy | `IfNotPresent` |
| `service.type` | node service type | `NodePort` |
| `service.port` | node service port | `80` |
| `service.targetPort` | node service targetPort | `80` |
| `service.nodePort` | node service nodePort | `30001` |
| `config.enabled` | If apply custom config file to node service | `True` |
| `config.content` | custom file content | `your own custom conf` |
| `config.name` | config volume name | `nodejs-mount` |
| `ingress.enabled` | Enable ingress controller resource | `false` |
| `ingress.hosts[0].host` | Host to your Node installation | `chart-example.local` |
| `ingress.hosts[0].paths` | Path within the url structure | `[]` |
| `ingress.hosts[0].tls` | Utilize TLS backend in ingress | `[]` |
| `ingress.hosts[0].annotations` | Annotations for this host's ingress record | `{}` |
<!-- Required -->
## Licenses
All licenses for the Clear Linux* Project and distributed software can be found
at https://clearlinux.org/terms-and-policies
+21
View File
@@ -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 "node.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 "node.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "node.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 "node.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 port-forward $POD_NAME 8080:80
{{- end }}
+56
View File
@@ -0,0 +1,56 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "node.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 "node.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 "node.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "node.labels" -}}
app.kubernetes.io/name: {{ include "node.name" . }}
helm.sh/chart: {{ include "node.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "node.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "node.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
+12
View File
@@ -0,0 +1,12 @@
{{- if .Values.config.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "node.fullname" . }}
labels:
{{ include "node.labels" . | indent 4 }}
data:
app.js: |-
{{ .Values.config.content | indent 4 }}
{{- end }}
+33
View File
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "node.fullname" . }}
labels:
{{ include "node.labels" . | indent 4 }}
spec:
replicas: {{ .Values.image.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "node.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "node.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: node
image: {{ .Values.image.repository }}
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
ports:
- containerPort: {{ .Values.service.port }}
command: ["node", "/app.js"]
volumeMounts:
- name: {{ .Values.config.name }}
mountPath: /app.js
subPath: app.js
volumes:
- name: {{ .Values.config.name }}
configMap:
name: {{ include "node.fullname" . }}
+15
View File
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "node.fullname" . }}
labels:
{{ include "node.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
nodePort: {{ .Values.service.nodePort }}
selector:
app.kubernetes.io/name: {{ include "node.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
+45
View File
@@ -0,0 +1,45 @@
# Default values for node.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
image:
replicaCount: 2
repository: docker.io/clearlinux/node
imagePullPolicy: IfNotPresent
service:
type: NodePort
port: 80
targetPort: 80
nodePort: 30001
config:
enabled: True
name: nodejs-mount
content: |-
const http = require('http');
const os = require('os');
var handler = function(request, response){
response.writeHead(200);
response.end("Hello nodejs!\n")
};
var www = http.createServer(handler);
www.listen(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