创建自己的helm chart仓库

pull/62/head
Jimmy Song 2017-10-25 17:10:36 +08:00
parent ac9faa18dd
commit c730f8ed46
27 changed files with 1122 additions and 21 deletions

View File

@ -88,7 +88,7 @@
- [4.4.2 CephFS](practice/cephfs.md) - [4.4.2 CephFS](practice/cephfs.md)
- [4.4.2.1 使用Ceph做持久化存储](practice/using-ceph-for-persistent-storage.md) - [4.4.2.1 使用Ceph做持久化存储](practice/using-ceph-for-persistent-storage.md)
- [4.5 服务编排管理](practice/services-management-tool.md) - [4.5 服务编排管理](practice/services-management-tool.md)
- [4.5.1 Helm](practice/helm.md) - [4.5.1 使用Helm管理kubernetes应用](practice/helm.md)
- [5. 领域应用](usecases/index.md) - [5. 领域应用](usecases/index.md)
- [5.1 微服务架构](usecases/microservices.md) - [5.1 微服务架构](usecases/microservices.md)
- [5.1.1 微服务中的服务发现](usecases/service-discovery-in-microservices.md) - [5.1.1 微服务中的服务发现](usecases/service-discovery-in-microservices.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -0,0 +1,19 @@
name: mean
version: 0.1.3
description: MEAN is a free and open-source JavaScript software stack for building dynamic web sites and web applications. The MEAN stack is MongoDB, Express.js, Angular, and Node.js. Because all components of the MEAN stack support programs written in JavaScript, MEAN applications can be written in one language for both server-side and client-side execution environments.
keywords:
- node
- javascript
- mongodb
- express
- angular
- nodejs
- git
home: http://nodejs.org/
sources:
- https://github.com/bitnami/bitnami-docker-node
maintainers:
- name: Bitnami
email: containers@bitnami.com
engine: gotpl
icon: https://bitnami.com/assets/stacks/meanstack/img/meanstack-stack-220x234.png

View File

@ -0,0 +1,101 @@
# NodeJS
[NodeJS](https://www.nodejs.org) The MEAN stack is MongoDB, Express.js, Angular, and Node.js. Because all components of the MEAN stack support programs written in JavaScript, MEAN applications can be written in one language for both server-side and client-side execution environments.
## TL;DR;
```console
$ helm install incubator/mean
```
## Introduction
This chart bootstraps a [NodeJS](https://github.com/bitnami/bitnami-docker-node) and a [MongoDB](https://github.com/bitnami/bitnami-docker-mongodb) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
It clones and deploys a Node.js application from a git repository. Defaults to a demo MEAN application: https://github.com/scotch-io/node-todo.git
## Prerequisites
- Kubernetes 1.4+ with Beta APIs enabled
- PV provisioner support in the underlying infrastructure
## Installing the Chart
To install the chart with the release name `my-release`:
```console
$ helm install --name my-release incubator/mean
```
The command deploys Node.js on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation. Also includes support for MongoDB chart out of the box.
Due that the Helm Chart clones the application on the /app volume while the container is initializing, a persistent volume is not required.
> **Tip**: List all releases using `helm list`
## Uninstalling the Chart
To uninstall/delete the `my-release` deployment:
```console
$ helm delete my-release
```
The command removes all the Kubernetes components associated with the chart and deletes the release.
## Configuration
The following tables lists the configurable parameters of the NodeJS chart and their default values.
| Parameter | Description | Default |
|------------------------------------|-------------------------------------|-----------------------------------------------------------|
| `image` | NodeJS image | `bitnami/node:{VERSION}` |
| `imagePullPolicy` | Image pull policy | `IfNotPresent` |
| `repository` | Repo of the application | `https://github.com/scotch-io/node-todo.git` |
| `revision` | Revision to checkout | `master` |
| `config` | Contents of the config file for app | `See repo file config/database.js` |
| `configfile` | Filename of config file for app | `database.js` |
| `mongodb.mongodbRootPassword` | MongoDB admin password | `nil` |
| `mongodb.mongodbUsername` | MongoDB username | `nil` |
| `mongodb.mongodbPassword` | MongoDB username password | `nil` |
| `mongodb.mongodbDatabase` | MongoDB database name | `nil` |
| `mongodb.persistence.enabled` | MongoDB Persistent Volume enabled? | `false` |
| `mongodb.persistence.storageClass` | Type of storage for PVC | `default` |
| `mongodb.persistence.accessMode` | Type of access mode for PVC | `ReadWriteOnce` |
| `mongodb.persistence.size` | Disk size | `8Gi` |
| `serviceType` | Kubernetes Service type | `LoadBalancer` |
| `resources` | CPU/Memory resource requests/limits | Memory: `512Mi`, CPU: `300m` |
| `persistence.enabled` | NodeJS persistence enabled? | `false` |
| `persistence.storageClass` | Type of storage for PVC | If defined: |
| `volume.beta.kubernetes.io/storage-class: <storageClass>` |
| Defaults: |
| `volume.alpha.kubernetes.io/storage-class: default` |
|--------------------------------------------------------------------------------------------------------------------------------------|
The above parameters map to the env variables defined in [bitnami/node](http://github.com/bitnami/bitnami-docker-node). For more information please refer to the [bitnami/node](http://github.com/bitnami/bitnami-docker-node) image documentation.
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
```console
$ helm install --name my-release \
--set repository=https://github.com/scotch-io/node-todo.git,mongodb.mongodbRootPassword=secretpassword \
incubator/mean
```
The above command clones the remote git repository to the `/app/` directory of the container. Additionally it sets the MongoDB `root` user password to `secretpassword`.
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,
```console
$ helm install --name my-release -f values.yaml incubator/mean
```
> **Tip**: You can use the default [values.yaml](values.yaml)
## Persistence
The [Bitnami NodeJS](https://github.com/bitnami/bitnami-docker-node) image stores the NodeJS application and configurations at the `/app` path of the container.
This storage is ephemeral and it will disappear when the pods are taken away
Persistent Volume Claims are used to keep the data across deployments. This is known to work in GCE, AWS, and minikube.
See the [Configuration](#configuration) section to configure the PVC or to disable persistence.

View File

@ -0,0 +1 @@
.git

View File

@ -0,0 +1,17 @@
appVersion: 3.4.9
description: NoSQL document-oriented database that stores JSON-like documents with
dynamic schemas, simplifying the integration of data in content-driven applications.
engine: gotpl
home: https://mongodb.org
icon: https://bitnami.com/assets/stacks/mongodb/img/mongodb-stack-220x234.png
keywords:
- mongodb
- database
- nosql
maintainers:
- email: containers@bitnami.com
name: Bitnami
name: mongodb
sources:
- https://github.com/bitnami/bitnami-docker-mongodb
version: 0.4.17

View File

@ -0,0 +1,84 @@
# MongoDB
[MongoDB](https://www.mongodb.com/) is a cross-platform document-oriented database. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas, making the integration of data in certain types of applications easier and faster.
## TL;DR;
```bash
$ helm install stable/mongodb
```
## Introduction
This chart bootstraps a [MongoDB](https://github.com/bitnami/bitnami-docker-mongodb) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
## Prerequisites
- Kubernetes 1.4+ with Beta APIs enabled
- PV provisioner support in the underlying infrastructure
## Installing the Chart
To install the chart with the release name `my-release`:
```bash
$ helm install --name my-release stable/mongodb
```
The command deploys MongoDB on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.
> **Tip**: List all releases using `helm list`
## Uninstalling the Chart
To uninstall/delete the `my-release` deployment:
```bash
$ helm delete my-release
```
The command removes all the Kubernetes components associated with the chart and deletes the release.
## Configuration
The following tables lists the configurable parameters of the MongoDB chart and their default values.
| Parameter | Description | Default |
|----------------------------|-------------------------------------|----------------------------------------------------------|
| `image` | MongoDB image | `bitnami/mongodb:{VERSION}` |
| `imagePullPolicy` | Image pull policy | `Always` if `imageTag` is `latest`, else `IfNotPresent`. |
| `mongodbRootPassword` | MongoDB admin password | `nil` |
| `mongodbUsername` | MongoDB custom user | `nil` |
| `mongodbPassword` | MongoDB custom user password | `nil` |
| `mongodbDatabase` | Database to create | `nil` |
| `serviceType` | Kubernetes Service type | `ClusterIP` |
| `persistence.enabled` | Use a PVC to persist data | `true` |
| `persistence.storageClass` | Storage class of backing PVC | `nil` (uses alpha storage class annotation) |
| `persistence.accessMode` | Use volume as ReadOnly or ReadWrite | `ReadWriteOnce` |
| `persistence.size` | Size of data volume | `8Gi` |
The above parameters map to the env variables defined in [bitnami/mongodb](http://github.com/bitnami/bitnami-docker-mongodb). For more information please refer to the [bitnami/mongodb](http://github.com/bitnami/bitnami-docker-mongodb) image documentation.
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
```bash
$ helm install --name my-release \
--set mongodbRootPassword=secretpassword,mongodbUsername=my-user,mongodbPassword=my-password,mongodbDatabase=my-database \
stable/mongodb
```
The above command sets the MongoDB `root` account password to `secretpassword`. Additionally it creates a standard database user named `my-user`, with the password `my-password`, who has access to a database named `my-database`.
Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,
```bash
$ helm install --name my-release -f values.yaml stable/mongodb
```
> **Tip**: You can use the default [values.yaml](values.yaml)
## Persistence
The [Bitnami MongoDB](https://github.com/bitnami/bitnami-docker-mongodb) image stores the MongoDB data and configurations at the `/bitnami/mongodb` path of the container.
The chart mounts a [Persistent Volume](http://kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning.

View File

@ -0,0 +1,7 @@
MongoDB can be accessed via port 27017 on the following DNS name from within your cluster:
{{ template "mongodb.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
To connect to your database run the following command:
kubectl run {{ template "mongodb.fullname" . }}-client --rm --tty -i --image bitnami/mongodb --command -- mongo --host {{ template "mongodb.fullname" . }} {{- if .Values.mongodbRootPassword }} -p {{ .Values.mongodbRootPassword }}{{- end -}}

View File

@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "mongodb.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).
*/}}
{{- define "mongodb.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

View File

@ -0,0 +1,66 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "mongodb.fullname" . }}
labels:
app: {{ template "mongodb.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
template:
metadata:
labels:
app: {{ template "mongodb.fullname" . }}
spec:
containers:
- name: {{ template "mongodb.fullname" . }}
image: "{{ .Values.image }}"
imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
env:
- name: MONGODB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "mongodb.fullname" . }}
key: mongodb-root-password
- name: MONGODB_USERNAME
value: {{ default "" .Values.mongodbUsername | quote }}
- name: MONGODB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "mongodb.fullname" . }}
key: mongodb-password
- name: MONGODB_DATABASE
value: {{ default "" .Values.mongodbDatabase | quote }}
ports:
- name: mongodb
containerPort: 27017
livenessProbe:
exec:
command:
- mongo
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 30
timeoutSeconds: 5
readinessProbe:
exec:
command:
- mongo
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 5
timeoutSeconds: 1
volumeMounts:
- name: data
mountPath: /bitnami/mongodb
resources:
{{ toYaml .Values.resources | indent 10 }}
volumes:
- name: data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ template "mongodb.fullname" . }}
{{- else }}
emptyDir: {}
{{- end -}}

View File

@ -0,0 +1,19 @@
{{- if .Values.persistence.enabled }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "mongodb.fullname" . }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "mongodb.fullname" . }}
labels:
app: {{ template "mongodb.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
type: Opaque
data:
mongodb-root-password: {{ default "" .Values.mongodbRootPassword | b64enc | quote }}
mongodb-password: {{ default "" .Values.mongodbPassword | b64enc | quote }}

View File

@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "mongodb.fullname" . }}
labels:
app: {{ template "mongodb.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
type: {{ .Values.serviceType }}
ports:
- name: mongodb
port: 27017
targetPort: mongodb
selector:
app: {{ template "mongodb.fullname" . }}

View File

@ -0,0 +1,49 @@
## Bitnami MongoDB image version
## ref: https://hub.docker.com/r/bitnami/mongodb/tags/
##
image: sz-pg-oam-docker-hub-001.tendcloud.com/library/bitnami-mongodb:3.4.9-r1
## Specify a imagePullPolicy
## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
# imagePullPolicy:
## MongoDB admin password
## ref: https://github.com/bitnami/bitnami-docker-mongodb/blob/master/README.md#setting-the-root-password-on-first-run
##
# mongodbRootPassword:
## MongoDB custom user and database
## ref: https://github.com/bitnami/bitnami-docker-mongodb/blob/master/README.md#creating-a-user-and-database-on-first-run
##
# mongodbUsername:
# mongodbPassword:
# mongodbDatabase:
## Kubernetes service type
serviceType: ClusterIP
## Enable persistence using Persistent Volume Claims
## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
##
persistence:
enabled: false
## mongodb data Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
storageClass: "null"
accessMode: ReadWriteOnce
size: 8Gi
## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
requests:
memory: 256Mi
cpu: 100m

View File

@ -0,0 +1,10 @@
dependencies:
- condition: ""
enabled: false
import-values: null
name: mongodb
repository: http://localhost:8879/
tags: null
version: 0.4.17
digest: sha256:955f80c2844df5fb24c06440898df8d3b2143d7081ac11409d8604720e47b814
generated: 2017-10-24T11:45:19.054114+08:00

View File

@ -0,0 +1,4 @@
dependencies:
- name: mongodb
repository: http://localhost:8879
version: 0.4.x

View File

@ -0,0 +1,23 @@
Get the URL of your Node app by running:
{{- if contains "NodePort" .Values.serviceType }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "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.serviceType }}
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP/
It may take a few minutes for the LoadBalancer IP address to be available.
Watch the status with: 'kubectl get svc -w {{ template "fullname" . }} --namespace {{ .Release.Namespace }}'
{{- else if contains "ClusterIP" .Values.serviceType }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "fullname" . }}" -o jsonpath="{.items[0].metadata.name}")
echo http://127.0.0.1:8080/
kubectl port-forward $POD_NAME 8080:80
{{- end }}

View File

@ -0,0 +1,24 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 | trimSuffix "-" chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 | trimSuffix "-" chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "mongodb.fullname" -}}
{{- printf "%s-%s" .Release.Name "mongodb" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

View File

@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
{{ default "database.js" .Values.configfile}}: |-
{{- if .Values.config }}
{{ default "" .Values.config | indent 4 }}
{{- end -}}

View File

@ -0,0 +1,136 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
replicas: 1
template:
metadata:
labels:
app: {{ template "fullname" . }}
annotations:
pod.beta.kubernetes.io/init-containers: '[
{
"name": "wait-for-db-service",
"image": "{{ .Values.image }}",
"imagePullPolicy": "{{ .Values.imagePullPolicy }}",
"command": ["/bin/bash", "-c", "for i in {1..100}; do if nc -z -w 1 {{ template "mongodb.fullname" . }} 27017; then exit 0; fi; done; exit 1;"]
},
{
"name": "git-clone-app",
"image": "{{ .Values.image }}",
"imagePullPolicy": "{{ .Values.imagePullPolicy }}",
"command": [ "/bin/sh", "-c" , "git clone {{ .Values.repository }} /app && git checkout {{ .Values.revision }}" ],
"volumeMounts": [
{
"name": "app",
"mountPath": "/app"
}
]
},
{
"name": "npm-install",
"image": "{{ .Values.image }}",
"imagePullPolicy": "{{ .Values.imagePullPolicy }}",
"command": [ "/bin/sh", "-c" , "npm install" ],
"volumeMounts": [
{
"name": "app",
"mountPath": "/app"
}
]
},
{
"name": "fixing-permissions",
"image": "{{ .Values.image }}",
"imagePullPolicy": "{{ .Values.imagePullPolicy }}",
"command": [ "/bin/sh", "-c" , "chown bitnami:bitnami -R /app /home/bitnami {{ .Values.persistence.path }}"],
"volumeMounts": [
{
"name": "app",
"mountPath": "/app"
},
{
"name": "data",
"mountPath": "{{ .Values.persistence.path }}"
}
]
}
]'
spec:
containers:
- name: {{ template "fullname" . }}
securityContext:
readOnlyRootFilesystem: true
image: "{{ .Values.image }}"
imagePullPolicy: {{ default "" .Values.imagePullPolicy | quote }}
env:
- name: MONGODB_HOST
value: {{ template "mongodb.fullname" . }}
- name: MONGODB_PORT
value: "27017"
- name: MONGODB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "mongodb.fullname" . }}
key: mongodb-root-password
- name: MONGODB_USERNAME
value: {{ default "" .Values.mongodb.mongodbUsername | quote }}
- name: MONGODB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "mongodb.fullname" . }}
key: mongodb-password
- name: MONGODB_DATABASE
value: {{ default "" .Values.mongodb.mongodbDatabase | quote }}
- name: GIT_REPO
value: {{ .Values.repository }}
command:
- /bin/bash
- -ec
- sudo -HEu bitnami npm start
ports:
- name: http
containerPort: 8080
livenessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 180
timeoutSeconds: 5
failureThreshold: 6
readinessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 30
timeoutSeconds: 3
periodSeconds: 5
volumeMounts:
- name: app
mountPath: /app
- name: data
mountPath: {{ .Values.persistence.path }}
- name: config
mountPath: /app/config
volumes:
- name: app
emptyDir: {}
- name: data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ template "fullname" . }}
{{- else }}
emptyDir: {}
{{- end }}
- name: config
configMap:
name: {{ template "fullname" . }}
items:
- key: {{ .Values.configfile | quote }}
path: {{ .Values.configfile | quote }}

View File

@ -0,0 +1,26 @@
{{- if .Values.persistence.enabled }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
{{- if .Values.persistence.storageClass }}
volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass | quote }}
{{- else }}
volume.alpha.kubernetes.io/storage-class: default
{{- end }}
{{- range $key, $value := .Values.persistence.annotations }}
{{ $key }}: {{ $value }}
{{- end }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- end }}

View File

@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
type: {{ .Values.serviceType }}
ports:
- name: http
port: 80
targetPort: http
selector:
app: {{ template "fullname" . }}

View File

@ -0,0 +1,81 @@
## Bitnami node image version
## ref: https://hub.docker.com/r/bitnami/node/tags/
##
image: sz-pg-oam-docker-hub-001.tendcloud.com/library/bitnami-node:7.5.0-r0
## Git repository http/https
##
repository: https://github.com/scotch-io/node-todo.git
## Git repository revision to checkout
##
revision: 5750cb4
## Specify a imagePullPolicy
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
imagePullPolicy: IfNotPresent
## Configure the application with a custom config file
## ref: https://github.com/scotch-io/node-todo#installation
##
config: |-
module.exports = {
remoteUrl: "mongodb://" + process.env.MONGODB_USERNAME +":" + process.env.MONGODB_PASSWORD + "@" + process.env.MONGODB_HOST +":"+ process.env.MONGODB_PORT + "/" + process.env.MONGODB_DATABASE ,
localUrl: "mongodb://" + process.env.MONGODB_USERNAME +":" + process.env.MONGODB_PASSWORD + "@" + process.env.MONGODB_HOST +":"+ process.env.MONGODB_PORT + "/" + process.env.MONGODB_DATABASE
};
configfile: database.js
##
## MongoDB chart configuration
##
mongodb:
## MongoDB admin password
## ref: https://github.com/bitnami/bitnami-docker-MongoDB/blob/master/README.md#setting-the-root-password-on-first-run
# mongodbRootPassword:
## MongoDB custom user and database
## ref: https://github.com/bitnami/bitnami-docker-mongodb/blob/master/README.md#creating-a-user-and-database-on-first-run
##
# mongodbUsername:
# mongodbPassword:
# mongodbDatabase:
## Enable persistence using Persistent Volume Claims
## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
##
persistence:
enabled: false
## If defined, volume.beta.kubernetes.io/storage-class: <storageClass>
## Default: volume.alpha.kubernetes.io/storage-class: default
##
storageClass: "null"
accessMode: ReadWriteOnce
size: 8Gi
## Kubernetes configuration
## For minikube, set this to NodePort, elsewhere use LoadBalancer
##
serviceType: ClusterIP
## Enable persistence using Persistent Volume Claims
## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
##
persistence:
enabled: false
path: /app/data
## If defined, volume.beta.kubernetes.io/storage-class: <storageClass>
## Default: volume.alpha.kubernetes.io/storage-class: default
##
storageClass: "null"
accessMode: ReadWriteOnce
size: 1Gi
## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
requests:
memory: 512Mi
cpu: 300m

View File

@ -3,8 +3,8 @@
# Declare variables to be passed into your templates. # Declare variables to be passed into your templates.
replicaCount: 1 replicaCount: 1
image: image:
repository: nginx repository: sz-pg-oam-docker-hub-001.tendcloud.com/library/nginx
tag: stable tag: 1.9
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
service: service:
name: nginx name: nginx

View File

@ -33,3 +33,12 @@ spec:
backend: backend:
serviceName: k8s-app-monitor-agent serviceName: k8s-app-monitor-agent
servicePort: 8080 servicePort: 8080
- host: mean.jimmysong.io
http:
paths:
- path: /
backend:
serviceName: orbiting-platypus-mean
servicePort: 80

View File

@ -1,5 +1,7 @@
# 使用Helm管理kubernetes应用 # 使用Helm管理kubernetes应用
读完本文后您应该可以自己创建chart并创建自己的私有chart仓库。
Helm是一个kubernetes应用的包管理工具用来管理[charts](https://github.com/kubernetes/charts)——预先配置好的安装包资源有点类似于Ubuntu的APT和CentOS中的yum。 Helm是一个kubernetes应用的包管理工具用来管理[charts](https://github.com/kubernetes/charts)——预先配置好的安装包资源有点类似于Ubuntu的APT和CentOS中的yum。
Helm chart是用来封装kubernetes原生应用程序的yaml文件可以在你部署应用的时候自定义应用程序的一些metadata便与应用程序的分发。 Helm chart是用来封装kubernetes原生应用程序的yaml文件可以在你部署应用的时候自定义应用程序的一些metadata便与应用程序的分发。
@ -15,7 +17,11 @@ Helm和charts的主要作用
**前提要求** **前提要求**
Kubernetes1.5以上版本,集群可访问到的镜像仓库。 - Kubernetes1.5以上版本
- 集群可访问到的镜像仓库
- 执行helm命令的主机可以访问到kubernetes集群
**安装步骤**
首先需要安装helm客户端 首先需要安装helm客户端
@ -64,14 +70,14 @@ Server: &version.Version{SemVer:"v2.3.1", GitCommit:"32562a3040bb5ca690339b9840b
$ helm create mongodb $ helm create mongodb
$ tree mongodb $ tree mongodb
mongodb mongodb
├── Chart.yaml ├── Chart.yaml #Chart本身的版本和配置信息
├── charts ├── charts #依赖的chart
├── templates ├── templates #配置模板目录
│   ├── NOTES.txt │   ├── NOTES.txt #helm提示信息
│   ├── _helpers.tpl │   ├── _helpers.tpl #用于修改kubernetes objcet配置的模板
│   ├── deployment.yaml │   ├── deployment.yaml #kubernetes Deployment object
│   └── service.yaml │   └── service.yaml #kubernetes Serivce
└── values.yaml └── values.yaml #kubernetes object configuration
2 directories, 6 files 2 directories, 6 files
``` ```
@ -146,6 +152,8 @@ resources:
以上两个变量值是在create chart的时候自动生成的默认值。 以上两个变量值是在create chart的时候自动生成的默认值。
我们将默认的镜像地址和tag改成我们自己的镜像`sz-pg-oam-docker-hub-001.tendcloud.com/library/nginx:1.9`。
### 检查配置和模板是否有效 ### 检查配置和模板是否有效
当使用kubernetes部署应用的时候实际上讲templates渲染成最终的kubernetes能够识别的yaml格式。 当使用kubernetes部署应用的时候实际上讲templates渲染成最终的kubernetes能够识别的yaml格式。
@ -157,7 +165,7 @@ $ helm install --dry-run --debug mychart
Created tunnel using local port: '58406' Created tunnel using local port: '58406'
SERVER: "localhost:58406" SERVER: "localhost:58406"
CHART PATH: /Users/jimmy/Workspace/github/bitnami/charts/incubator/mean/charts/mychart CHART PATH: /Users/jimmy/Workspace/github/bitnami/charts/incubator/mean/charts/mychart
NAME: named-jackal NAME: filled-seahorse
REVISION: 1 REVISION: 1
RELEASED: Tue Oct 24 18:57:13 2017 RELEASED: Tue Oct 24 18:57:13 2017
CHART: mychart-0.1.0 CHART: mychart-0.1.0
@ -167,8 +175,8 @@ USER-SUPPLIED VALUES:
COMPUTED VALUES: COMPUTED VALUES:
image: image:
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
repository: nginx repository: sz-pg-oam-docker-hub-001.tendcloud.com/library/nginx
tag: stable tag: 1.9
replicaCount: 1 replicaCount: 1
resources: resources:
limits: limits:
@ -191,7 +199,7 @@ MANIFEST:
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: named-jackal-mychart name: filled-seahorse-mychart
labels: labels:
chart: "mychart-0.1.0" chart: "mychart-0.1.0"
spec: spec:
@ -202,14 +210,14 @@ spec:
protocol: TCP protocol: TCP
name: nginx name: nginx
selector: selector:
app: named-jackal-mychart app: filled-seahorse-mychart
--- ---
# Source: mychart/templates/deployment.yaml # Source: mychart/templates/deployment.yaml
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
kind: Deployment kind: Deployment
metadata: metadata:
name: named-jackal-mychart name: filled-seahorse-mychart
labels: labels:
chart: "mychart-0.1.0" chart: "mychart-0.1.0"
spec: spec:
@ -217,11 +225,11 @@ spec:
template: template:
metadata: metadata:
labels: labels:
app: named-jackal-mychart app: filled-seahorse-mychart
spec: spec:
containers: containers:
- name: mychart - name: mychart
image: "nginx:stable" image: "sz-pg-oam-docker-hub-001.tendcloud.com/library/nginx:1.9"
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
ports: ports:
- containerPort: 80 - containerPort: 80
@ -242,7 +250,105 @@ spec:
memory: 128Mi memory: 128Mi
``` ```
## 部署todo测试案例 我们可以看到Deployment和Service的名字前半截由两个随机的单词组成最后才是我们在`values.yaml`中配置的值。
### 部署到kubernetes
在`mychart`目录下执行下面的命令将nginx部署到kubernetes集群上。
```bash
helm install .
NAME: eating-hound
LAST DEPLOYED: Wed Oct 25 14:58:15 2017
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
eating-hound-mychart 10.254.135.68 <none> 80/TCP 0s
==> extensions/v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
eating-hound-mychart 1 1 1 0 0s
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app=eating-hound-mychart" -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
```
现在nginx已经部署到kubernetes集群上本地执行提示中的命令在本地主机上访问到nginx实例。
```bash
export POD_NAME=$(kubectl get pods --namespace default -l "app=eating-hound-mychart" -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
```
在本地访问`http://127.0.0.1:8080`即可访问到nginx。
**查看部署的relaese**
```bash
$ helm list
NAME REVISION UPDATED STATUS CHART NAMESPACE
eating-hound 1 Wed Oct 25 14:58:15 2017 DEPLOYED mychart-0.1.0 default
```
**删除部署的release**
```bash
$ helm delete eating-hound
release "eating-hound" deleted
```
### 打包分享
我们可以修改`Chart.yaml`中的helm chart配置信息然后使用下列命令将chart打包成一个压缩文件。
```bash
helm package .
```
打包出`mychart-0.1.0.tgz`文件。
### 依赖
我们可以在`requirement.yaml`中定义应用所依赖的chart例如定义对`mariadb`的依赖:
```yaml
dependencies:
- name: mariadb
version: 0.6.0
repository: https://kubernetes-charts.storage.googleapis.com
```
使用`helm lint . `命令可以检查依赖和模板配置是否正确。
### 安装源
我们在前面安装chart可以通过HTTP server的方式提供。
```bash
$ helm serve
Regenerating index. This may take a moment.
Now serving you on 127.0.0.1:8879
```
访问`http://localhost:8879`可以看到刚刚安装的chart。
![Helm chart源](../images/helm-charts-repository.jpg)
点击链接即可以下载chart的压缩包。
## 部署MEAN测试案例
MEAN是用来构建网站和web应用的免费开源的JavaScript软件栈该软件栈包括MongoDB、Express.js、Angular和Node.js。
**下载charts**
```bash ```bash
$ git clone https://github.com/bitnami/charts.git $ git clone https://github.com/bitnami/charts.git
@ -254,6 +360,8 @@ mongodb 0.4.x https://kubernetes-charts.storage.googleapis.com/ missing
缺少mongodb的依赖需要更新一下chart。 缺少mongodb的依赖需要更新一下chart。
**注**`https://kubernetes-charts.storage.googleapis.com/`是Google维护的chart库访问该地址可以看到所有的chart列表。
```bash ```bash
$ helm dep update $ helm dep update
Hang tight while we grab the latest from your chart repositories... Hang tight while we grab the latest from your chart repositories...
@ -280,9 +388,249 @@ Saving 1 charts
Downloading mongodb from repo https://kubernetes-charts.storage.googleapis.com/ Downloading mongodb from repo https://kubernetes-charts.storage.googleapis.com/
``` ```
**修改mongodb chart配置**
将刚才下载的`charts/mongodb-0.4.17.tgz`给解压后,修改其中的配置:
- 将`persistence`下的`enabled`设置为false
- 将image修改为我们的私有镜像sz-pg-oam-docker-hub-001.tendcloud.com/library/bitnami-mongodb:3.4.9-r1
执行`helm install --dry-run --debug .`确定模板无误。
将修改后的mongodb chart打包在mongodb的目录下执行
```bash
helm package .
```
现在再访问前面启动的helm server `http://localhost:8879`将可以在页面上看到mongodb-0.4.17这个chart。
我们对官方chart配置做了如下修改后推送到了自己的chart仓库
- `requirements.yaml`和`requirements.lock`文件中的`repository`为`http://localhost:8879`
- 将`values.yaml`中的`storageClass`设置为`null`
- 将`values.yaml`中的`Image`都改为私有镜像
- `repositroy`都设置为`http://localhost:8879`
**注**因为我们没有使用PVC所以将所有的关于持久化存储的配置都设置为false了。
**部署MEAN**
在`mean`目录下执行:
```bash
helm install .
NAME: orbiting-platypus
LAST DEPLOYED: Wed Oct 25 16:21:48 2017
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Secret
NAME TYPE DATA AGE
orbiting-platypus-mongodb Opaque 2 2s
==> v1/ConfigMap
NAME DATA AGE
orbiting-platypus-mean 1 2s
==> v1/Service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
orbiting-platypus-mongodb 10.254.144.208 <none> 27017/TCP 2s
orbiting-platypus-mean 10.254.165.23 <none> 80/TCP 2s
==> extensions/v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
orbiting-platypus-mean 1 1 1 0 2s
orbiting-platypus-mongodb 1 1 1 0 2s
NOTES:
Get the URL of your Node app by running:
export POD_NAME=$(kubectl get pods --namespace default -l "app=orbiting-platypus-mean" -o jsonpath="{.items[0].metadata.name}")
echo http://127.0.0.1:8080/
kubectl port-forward $POD_NAME 8080:80
```
这样MEAN软件栈就部署到你的kuberentes集群里面了默认是在default namespace下
**验证检查**
为了验证MEAN是否安装成功过可以使用`kubectl get pods`查看pod是否启动完成会先启动mongodb的pod然后启动MEAN中的4步init。
**访问Web UI**
在Ingress中增加如下配置
```yaml
- host: mean.jimmysong.io
http:
paths:
- backend:
serviceName: orbiting-platypus-mean
servicePort: 80
path: /
```
然后在页面中更新ingress:
```bash
kubectl repalce -f ingress.yaml
```
关于Ingress配置请参考[边缘节点配置](../practice/edge-node-configuration.md)
然后在本地的`/etc/hosts`文件中增加一条配置:
```Ini
172.20.0.119 mean.jimmysong.io
```
**注**172.20.0.119即边缘节点的VIP。
因为该页面需要加载google的angularjs、还有两个css在国内无法访问可以使用curl测试
```bash
curl mean.jimmysong.io
```
将会返回HTML内容
```html
<!doctype html>
<!-- ASSIGN OUR ANGULAR MODULE -->
<html ng-app="scotchTodo">
<head>
<!-- META -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Optimize mobile viewport -->
<title>Node/Angular Todo App</title>
<!-- SCROLLS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<!-- load bootstrap -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">
<style>
html {
overflow-y: scroll;
}
body {
padding-top: 50px;
}
#todo-list {
margin-bottom: 30px;
}
#todo-form {
margin-bottom: 50px;
}
</style>
<!-- SPELLS -->
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<!-- load angular -->
<script src="js/controllers/main.js"></script>
<!-- load up our controller -->
<script src="js/services/todos.js"></script>
<!-- load our todo service -->
<script src="js/core.js"></script>
<!-- load our main application -->
</head>
<!-- SET THE CONTROLLER -->
<body ng-controller="mainController">
<div class="container">
<!-- HEADER AND TODO COUNT -->
<div class="jumbotron text-center">
<h1>I'm a Todo-aholic <span class="label label-info">{{ todos.length }}</span></h1>
</div>
<!-- TODO LIST -->
<div id="todo-list" class="row">
<div class="col-sm-4 col-sm-offset-4">
<!-- LOOP OVER THE TODOS IN $scope.todos -->
<div class="checkbox" ng-repeat="todo in todos">
<label>
<input type="checkbox" ng-click="deleteTodo(todo._id)"> {{ todo.text }}
</label>
</div>
<p class="text-center" ng-show="loading">
<span class="fa fa-spinner fa-spin fa-3x"></span>
</p>
</div>
</div>
<!-- FORM TO CREATE TODOS -->
<div id="todo-form" class="row">
<div class="col-sm-8 col-sm-offset-2 text-center">
<form>
<div class="form-group">
<!-- BIND THIS VALUE TO formData.text IN ANGULAR -->
<input type="text" class="form-control input-lg text-center" placeholder="I want to buy a puppy that will love me forever" ng-model="formData.text">
</div>
<!-- createToDo() WILL CREATE NEW TODOS -->
<button type="submit" class="btn btn-primary btn-lg" ng-click="createTodo()">Add</button>
</form>
</div>
</div>
<div class="text-center text-muted">
<p>A demo by <a href="http://scotch.io">Scotch</a>.</p>
<p>Read the <a href="http://scotch.io/tutorials/javascript/creating-a-single-page-todo-app-with-node-and-angular">tutorial</a>.</p>
</div>
</div>
</body>
</html>
```
访问 http://mean.jimmysong.io 可以看到如下界面我在其中添加几条todo
![TODO应用的Web页面](../images/helm-mean-todo-aholic.jpg)
**注**Todo中的文字来自*What does the fox say*
测试完成后可以使用下面的命令将mean chart推送的本地chart仓库中。
在mean目录下执行
```bash
helm package .
```
再次刷新`http://localhost:8879`将可以看到如下三个chart
- mean
- mean-0.1.3
- mongodb
- mongodb-0.4.17
- mychart
- mychart-0.1.0
## 参考 ## 参考
- [Deploy, Scale And Upgrade An Application On Kubernetes With Helm](https://docs.bitnami.com/kubernetes/how-to/deploy-application-kubernetes-helm/) - [Deploy, Scale And Upgrade An Application On Kubernetes With Helm](https://docs.bitnami.com/kubernetes/how-to/deploy-application-kubernetes-helm/)
- [Helm charts](https://github.com/kubernetes/helm/blob/master/docs/charts.md) - [Helm charts](https://github.com/kubernetes/helm/blob/master/docs/charts.md)
- [Go template](https://golang.org/pkg/text/template/) - [Go template](https://golang.org/pkg/text/template/)
- [Helm docs](https://github.com/kubernetes/helm/blob/master/docs/index.md)
- [How To Create Your First Helm Chart](https://docs.bitnami.com/kubernetes/how-to/create-your-first-helm-chart/) - [How To Create Your First Helm Chart](https://docs.bitnami.com/kubernetes/how-to/create-your-first-helm-chart/)