创建helm chart说明
parent
7ea006bd67
commit
ac9faa18dd
|
@ -103,8 +103,35 @@ Sep 4 15:25:36 bj-xg-oam-kubernetes-001 kube-controller-manager: E0904 15:25:36
|
|||
|
||||
该问题尚未解决,参考 [Error creating rbd image: executable file not found in $PATH#38923](https://github.com/kubernetes/kubernetes/issues/38923)
|
||||
|
||||
## 9. Helm: Error: no available release name found
|
||||
|
||||
在开启了RBAC的kubernetes集群中,当使用helm部署应用,执行`helm install`的时候,会报着个错误:
|
||||
|
||||
```
|
||||
Error: no available release name found
|
||||
Error: the server does not allow access to the requested resource (get configmaps)
|
||||
```
|
||||
|
||||
这是因为我们使用的`2.3.1`版本的helm init的时候没有为tiller创建`serviceaccount`和`clusterrolebiding`的缘故导致的。
|
||||
|
||||
```bash
|
||||
kubectl create serviceaccount --namespace kube-system tiller
|
||||
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
|
||||
# helm init -i sz-pg-oam-docker-hub-001.tendcloud.com/library/kubernetes-helm-tiller:v2.3.1
|
||||
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
|
||||
```
|
||||
|
||||
**参考**
|
||||
|
||||
- [Helm: Error: no available release name found - StackOverflow](https://stackoverflow.com/questions/43499971/helm-error-no-available-release-name-found)
|
||||
- [Helm 2.2.3 not working properly with kubeadm 1.6.1 default RBAC rules #2224](https://github.com/kubernetes/helm/issues/2224)
|
||||
|
||||
|
||||
|
||||
## 参考
|
||||
|
||||
[Persistent Volume](https://kubernetes.io/docs/concepts/storage/persistent-volumes/)
|
||||
|
||||
[Resource Design Proposals](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/resources.md)
|
||||
|
||||
[Helm: Error: no available release name found]()
|
|
@ -0,0 +1 @@
|
|||
.git
|
|
@ -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
|
|
@ -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.
|
|
@ -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 -}}
|
||||
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 }}
|
|
@ -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 }}
|
|
@ -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" . }}
|
|
@ -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: "-"
|
||||
accessMode: ReadWriteOnce
|
||||
size: 8Gi
|
||||
|
||||
## Configure resource requests and limits
|
||||
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
|
||||
##
|
||||
resources:
|
||||
requests:
|
||||
memory: 256Mi
|
||||
cpu: 100m
|
|
@ -0,0 +1,21 @@
|
|||
# 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
|
|
@ -0,0 +1,4 @@
|
|||
apiVersion: v1
|
||||
description: A Helm chart for Kubernetes
|
||||
name: mychart
|
||||
version: 0.1.0
|
|
@ -0,0 +1,15 @@
|
|||
1. Get the application URL by running these commands:
|
||||
{{- if contains "NodePort" .Values.service.type }}
|
||||
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/login
|
||||
{{- 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 svc -w {{ template "fullname" . }}'
|
||||
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
|
||||
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
|
||||
{{- else if contains "ClusterIP" .Values.service.type }}
|
||||
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "fullname" . }}" -o jsonpath="{.items[0].metadata.name}")
|
||||
echo "Visit http://127.0.0.1:8080 to use your application"
|
||||
kubectl port-forward $POD_NAME 8080:{{ .Values.service.externalPort }}
|
||||
{{- end }}
|
|
@ -0,0 +1,16 @@
|
|||
{{/* 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 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 -}}
|
|
@ -0,0 +1,29 @@
|
|||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ template "fullname" . }}
|
||||
labels:
|
||||
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ template "fullname" . }}
|
||||
spec:
|
||||
containers:
|
||||
- name: {{ .Chart.Name }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- containerPort: {{ .Values.service.internalPort }}
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: {{ .Values.service.internalPort }}
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: {{ .Values.service.internalPort }}
|
||||
resources:
|
||||
{{ toYaml .Values.resources | indent 12 }}
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ template "fullname" . }}
|
||||
labels:
|
||||
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- port: {{ .Values.service.externalPort }}
|
||||
targetPort: {{ .Values.service.internalPort }}
|
||||
protocol: TCP
|
||||
name: {{ .Values.service.name }}
|
||||
selector:
|
||||
app: {{ template "fullname" . }}
|
|
@ -0,0 +1,21 @@
|
|||
# Default values for mychart.
|
||||
# This is a YAML-formatted file.
|
||||
# Declare variables to be passed into your templates.
|
||||
replicaCount: 1
|
||||
image:
|
||||
repository: nginx
|
||||
tag: stable
|
||||
pullPolicy: IfNotPresent
|
||||
service:
|
||||
name: nginx
|
||||
type: ClusterIP
|
||||
externalPort: 80
|
||||
internalPort: 80
|
||||
resources:
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
|
258
practice/helm.md
258
practice/helm.md
|
@ -2,13 +2,22 @@
|
|||
|
||||
Helm是一个kubernetes应用的包管理工具,用来管理[charts](https://github.com/kubernetes/charts)——预先配置好的安装包资源,有点类似于Ubuntu的APT和CentOS中的yum。
|
||||
|
||||
Helm chart是用来封装kubernetes原生应用程序的yaml文件,可以在你部署应用的时候自定义应用程序的一些metadata,便与应用程序的分发。
|
||||
|
||||
Helm和charts的主要作用:
|
||||
|
||||
- 应用程序封装
|
||||
- 版本管理
|
||||
- 依赖检查
|
||||
- 便于应用程序分发
|
||||
|
||||
## 安装Helm
|
||||
|
||||
**前提要求**
|
||||
|
||||
kubernetes1.5以上版本
|
||||
Kubernetes1.5以上版本,集群可访问到的镜像仓库。
|
||||
|
||||
首先需要安装helm客户端:
|
||||
首先需要安装helm客户端
|
||||
|
||||
```bash
|
||||
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
|
||||
|
@ -16,7 +25,14 @@ chmod 700 get_helm.sh
|
|||
./get_helm.sh
|
||||
```
|
||||
|
||||
然后安装helm服务端tiller:
|
||||
创建tiller的`serviceaccount`和`clusterrolebinding`
|
||||
|
||||
```bash
|
||||
kubectl create serviceaccount --namespace kube-system tiller
|
||||
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
|
||||
```
|
||||
|
||||
然后安装helm服务端tiller
|
||||
|
||||
```bash
|
||||
helm init -i sz-pg-oam-docker-hub-001.tendcloud.com/library/kubernetes-helm-tiller:v2.3.1
|
||||
|
@ -24,15 +40,249 @@ helm init -i sz-pg-oam-docker-hub-001.tendcloud.com/library/kubernetes-helm-till
|
|||
|
||||
我们使用`-i`指定自己的镜像,因为官方的镜像因为某些原因无法拉取。
|
||||
|
||||
为应用程序设置`serviceAccount`:
|
||||
|
||||
```bash
|
||||
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
|
||||
```
|
||||
|
||||
检查是否安装成功:
|
||||
|
||||
```bash
|
||||
kubectl -n kube-system get pods|grep tiller
|
||||
$ kubectl -n kube-system get pods|grep tiller
|
||||
tiller-deploy-2372561459-f6p0z 1/1 Running 0 1h
|
||||
$ helm version
|
||||
Client: &version.Version{SemVer:"v2.3.1", GitCommit:"32562a3040bb5ca690339b9840b6f60f8ce25da4", GitTreeState:"clean"}
|
||||
Server: &version.Version{SemVer:"v2.3.1", GitCommit:"32562a3040bb5ca690339b9840b6f60f8ce25da4", GitTreeState:"clean"}
|
||||
```
|
||||
|
||||
## 创建自己的chart
|
||||
|
||||
我们创建一个名为`mychart`的chart,看一看chart的文件结构。
|
||||
|
||||
```bash
|
||||
$ helm create mongodb
|
||||
$ tree mongodb
|
||||
mongodb
|
||||
├── Chart.yaml
|
||||
├── charts
|
||||
├── templates
|
||||
│ ├── NOTES.txt
|
||||
│ ├── _helpers.tpl
|
||||
│ ├── deployment.yaml
|
||||
│ └── service.yaml
|
||||
└── values.yaml
|
||||
|
||||
2 directories, 6 files
|
||||
```
|
||||
|
||||
### 模板
|
||||
|
||||
`Templates`目录下是yaml文件的模板,遵循[Go template](https://golang.org/pkg/text/template/)语法。使用过[Hugo](https://gohugo.io)的静态网站生成工具的人应该对此很熟悉。
|
||||
|
||||
我们查看下`deployment.yaml`文件的内容。
|
||||
|
||||
```yaml
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ template "fullname" . }}
|
||||
labels:
|
||||
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ template "fullname" . }}
|
||||
spec:
|
||||
containers:
|
||||
- name: {{ .Chart.Name }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- containerPort: {{ .Values.service.internalPort }}
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: {{ .Values.service.internalPort }}
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: {{ .Values.service.internalPort }}
|
||||
resources:
|
||||
{{ toYaml .Values.resources | indent 12 }}
|
||||
```
|
||||
|
||||
这是该应用的Deployment的yaml配置文件,其中的双大括号包扩起来的部分是Go template,其中的Values是在`values.yaml`文件中定义的:
|
||||
|
||||
```Yaml
|
||||
# Default values for mychart.
|
||||
# This is a YAML-formatted file.
|
||||
# Declare variables to be passed into your templates.
|
||||
replicaCount: 1
|
||||
image:
|
||||
repository: nginx
|
||||
tag: stable
|
||||
pullPolicy: IfNotPresent
|
||||
service:
|
||||
name: nginx
|
||||
type: ClusterIP
|
||||
externalPort: 80
|
||||
internalPort: 80
|
||||
resources:
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
```
|
||||
|
||||
比如在`Deployment.yaml`中定义的容器镜像`image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"`其中的:
|
||||
|
||||
- `.Values.image.repository`就是nginx
|
||||
- `.Values.image.tag`就是stable
|
||||
|
||||
以上两个变量值是在create chart的时候自动生成的默认值。
|
||||
|
||||
### 检查配置和模板是否有效
|
||||
|
||||
当使用kubernetes部署应用的时候实际上讲templates渲染成最终的kubernetes能够识别的yaml格式。
|
||||
|
||||
使用`helm install --dry-run --debug <chart_dir>`命令来验证chart配置。该输出中包含了模板的变量配置与最终渲染的yaml文件。
|
||||
|
||||
```bash
|
||||
$ helm install --dry-run --debug mychart
|
||||
Created tunnel using local port: '58406'
|
||||
SERVER: "localhost:58406"
|
||||
CHART PATH: /Users/jimmy/Workspace/github/bitnami/charts/incubator/mean/charts/mychart
|
||||
NAME: named-jackal
|
||||
REVISION: 1
|
||||
RELEASED: Tue Oct 24 18:57:13 2017
|
||||
CHART: mychart-0.1.0
|
||||
USER-SUPPLIED VALUES:
|
||||
{}
|
||||
|
||||
COMPUTED VALUES:
|
||||
image:
|
||||
pullPolicy: IfNotPresent
|
||||
repository: nginx
|
||||
tag: stable
|
||||
replicaCount: 1
|
||||
resources:
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
service:
|
||||
externalPort: 80
|
||||
internalPort: 80
|
||||
name: nginx
|
||||
type: ClusterIP
|
||||
|
||||
HOOKS:
|
||||
MANIFEST:
|
||||
|
||||
---
|
||||
# Source: mychart/templates/service.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: named-jackal-mychart
|
||||
labels:
|
||||
chart: "mychart-0.1.0"
|
||||
spec:
|
||||
type: ClusterIP
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
protocol: TCP
|
||||
name: nginx
|
||||
selector:
|
||||
app: named-jackal-mychart
|
||||
|
||||
---
|
||||
# Source: mychart/templates/deployment.yaml
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: named-jackal-mychart
|
||||
labels:
|
||||
chart: "mychart-0.1.0"
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: named-jackal-mychart
|
||||
spec:
|
||||
containers:
|
||||
- name: mychart
|
||||
image: "nginx:stable"
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 80
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
resources:
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
```
|
||||
|
||||
## 部署todo测试案例
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/bitnami/charts.git
|
||||
$ cd charts/incubator/mean
|
||||
$ helm dep list
|
||||
NAME VERSION REPOSITORY STATUS
|
||||
mongodb 0.4.x https://kubernetes-charts.storage.googleapis.com/ missing
|
||||
```
|
||||
|
||||
缺少mongodb的依赖,需要更新一下chart。
|
||||
|
||||
```bash
|
||||
$ helm dep update
|
||||
Hang tight while we grab the latest from your chart repositories...
|
||||
...Unable to get an update from the "local" chart repository (http://127.0.0.1:8879/charts):
|
||||
Get http://127.0.0.1:8879/charts/index.yaml: dial tcp 127.0.0.1:8879: getsockopt: connection refused
|
||||
...Successfully got an update from the "stable" chart repository
|
||||
Update Complete. ⎈Happy Helming!⎈
|
||||
Saving 1 charts
|
||||
Downloading mongodb from repo https://kubernetes-charts.storage.googleapis.com/
|
||||
```
|
||||
|
||||
所有的image都在 `values.yaml` 文件中配置。
|
||||
|
||||
下载缺失的chart。
|
||||
|
||||
```bash
|
||||
$ helm dep build
|
||||
Hang tight while we grab the latest from your chart repositories...
|
||||
...Unable to get an update from the "local" chart repository (http://127.0.0.1:8879/charts):
|
||||
Get http://127.0.0.1:8879/charts/index.yaml: dial tcp 127.0.0.1:8879: getsockopt: connection refused
|
||||
...Successfully got an update from the "stable" chart repository
|
||||
Update Complete. ⎈Happy Helming!⎈
|
||||
Saving 1 charts
|
||||
Downloading mongodb from repo https://kubernetes-charts.storage.googleapis.com/
|
||||
```
|
||||
|
||||
## 参考
|
||||
|
||||
- [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)
|
||||
- [Go template](https://golang.org/pkg/text/template/)
|
||||
- [How To Create Your First Helm Chart](https://docs.bitnami.com/kubernetes/how-to/create-your-first-helm-chart/)
|
Loading…
Reference in New Issue