[Reprint] helm example yaml file kubernetes actual articles of the details helm example yaml file kubernetes actual articles of the details

helm example yaml file kubernetes actual articles of the details

 
HTTPS: // www.cnblogs.com/tylerzhou/p/11141538.html 
Helm is a new era of application deployer

must learn before they can do.

 

Series catalog

In front of a complete sample, we mainly on the helm package, deploy, upgrade, rewind and other functions, the document on which there is only a brief introduction, this section we explain in detail there is documentation to help us to create your own reference helm chart .

Helm Chart Structure

Chart Directory Structure

mychart/
  Chart.yaml          # Yaml文件,用于描述Chart的基本信息,包括名称版本等
  LICENSE             # [可选] 协议
  README.md           # [可选] 当前Chart的介绍
  values.yaml         # Chart的默认配置文件
  requirements.yaml   # [可选] 用于存放当前Chart依赖的其它Chart的说明文件 charts/ # [可选]: 该目录中放置当前Chart依赖的其它Chart templates/ # [可选]: 部署文件模版目录,模版使用的值来自values.yaml和由Tiller提供的值 templates/NOTES.txt # [可选]: 放置Chart的使用指南

The chart generated by default if no changes are not so much.

Chart.yaml file

name: [必须] Chart的名称
version: [必须] Chart的版本号,版本号必须符合 SemVer 2:http://semver.org/
description: [可选] Chart的简要描述
keywords:
  -  [可选] 关键字列表,便于检索
home: [可选] 项目地址
sources:
  - [可选] 当前Chart的下载地址列表
maintainers: # [可选]
  - name: [必须] 名字
    email: [可选] 邮箱
engine: gotpl # [可选] 模版引擎,默认值是gotpl
icon: [可选] 一个SVG或PNG格式的图片地址

requirements.yaml directory and charts

requirements.yaml contents of the file:

dependencies:
  - name: example
    version: 1.2.3
    repository: http://example.com/charts
  - name: Chart名称
    version: Chart版本
    repository: 该Chart所在的仓库地址

Chart showing dependency supports two ways, or may be used directly dependent requirements.yaml placed charts Chart directory.

templates directory

templates stored in the template directory Kubernetes deployment files.
E.g:

# db.yaml
apiVersion: v1
kind: ReplicationController metadata:  name: deis-database  namespace: deis  labels:  heritage: deis spec:  replicas: 1  selector:  app: deis-database  template:  metadata:  labels:  app: deis-database  spec:  serviceAccount: deis-database  containers:  - name: deis-database  image: {{.Values.imageRegistry}}/postgres:{{.Values.dockerTag}}  imagePullPolicy: {{.Values.pullPolicy}}  ports:  - containerPort: 5432  env:  - name: DATABASE_STORAGE  value: {{default "minio" .Values.storage}}

Template syntax extension syntax golang / text / template is:

# 这种方式定义的模版,会去除test模版尾部所有的空行
{{- define "test"}}
模版内容
{{- end}}
 
# 去除test模版头部的第一个空行
{{- template "test" }}

Leading spaces for yaml file syntax:

# 这种方式定义的模版,会去除test模版头部和尾部所有的空行
{{- define "test" -}}
模版内容
{{- end -}}
 
# 可以在test模版每一行的头部增加4个空格,用于yaml文件的对齐
{{ include "test" | indent 4}}

Create your own chart

We created a chart called the mongodb, take a look at the file structure chart

$ helm create mongodb
$ tree mongodb
mongodb
├── Chart.yaml #Chart本身的版本和配置信息
├── charts #依赖的chart
├── templates #配置模板目录
│   ├── NOTES.txt #helm提示信息
│   ├── _helpers.tpl #用于修改kubernetes objcet配置的模板 │ ├── deployment.yaml #kubernetes Deployment object │ └── service.yaml #kubernetes Serivce └── values.yaml #kubernetes object configuration 2 directories, 6 files

template

Under Templates directory is yaml template file, follow Go template syntax. Used Hugo static website generation tools should be familiar with this.

We view the contents deployment.yaml file.

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 }}

This is yaml Deployment of the application profile, wherein the portion of the curly brackets bag is expanded up Go template, which is defined in the values.yaml Values ​​file:

# 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

Mirror image such as a container as defined in the Deployment.yaml: "{{.Values.image.repository}}: {{.Values.image.tag}}" where:

  • .Values.image.repository is nginx

  • .Values.image.tag is stable

Two or more variable values ​​are generated automatically create chart when the default value

Series catalog

In front of a complete sample, we mainly on the helm package, deploy, upgrade, rewind and other functions, the document on which there is only a brief introduction, this section we explain in detail there is documentation to help us to create your own reference helm chart .

Helm Chart Structure

Chart Directory Structure

mychart/
  Chart.yaml          # Yaml文件,用于描述Chart的基本信息,包括名称版本等
  LICENSE             # [可选] 协议
  README.md           # [可选] 当前Chart的介绍
  values.yaml         # Chart的默认配置文件
  requirements.yaml   # [可选] 用于存放当前Chart依赖的其它Chart的说明文件 charts/ # [可选]: 该目录中放置当前Chart依赖的其它Chart templates/ # [可选]: 部署文件模版目录,模版使用的值来自values.yaml和由Tiller提供的值 templates/NOTES.txt # [可选]: 放置Chart的使用指南

The chart generated by default if no changes are not so much.

Chart.yaml file

name: [必须] Chart的名称
version: [必须] Chart的版本号,版本号必须符合 SemVer 2:http://semver.org/
description: [可选] Chart的简要描述
keywords:
  -  [可选] 关键字列表,便于检索
home: [可选] 项目地址
sources:
  - [可选] 当前Chart的下载地址列表
maintainers: # [可选]
  - name: [必须] 名字
    email: [可选] 邮箱
engine: gotpl # [可选] 模版引擎,默认值是gotpl
icon: [可选] 一个SVG或PNG格式的图片地址

requirements.yaml directory and charts

requirements.yaml contents of the file:

dependencies:
  - name: example
    version: 1.2.3
    repository: http://example.com/charts
  - name: Chart名称
    version: Chart版本
    repository: 该Chart所在的仓库地址

Chart showing dependency supports two ways, or may be used directly dependent requirements.yaml placed charts Chart directory.

templates directory

templates stored in the template directory Kubernetes deployment files.
E.g:

# db.yaml
apiVersion: v1
kind: ReplicationController metadata:  name: deis-database  namespace: deis  labels:  heritage: deis spec:  replicas: 1  selector:  app: deis-database  template:  metadata:  labels:  app: deis-database  spec:  serviceAccount: deis-database  containers:  - name: deis-database  image: {{.Values.imageRegistry}}/postgres:{{.Values.dockerTag}}  imagePullPolicy: {{.Values.pullPolicy}}  ports:  - containerPort: 5432  env:  - name: DATABASE_STORAGE  value: {{default "minio" .Values.storage}}

Template syntax extension syntax golang / text / template is:

# 这种方式定义的模版,会去除test模版尾部所有的空行
{{- define "test"}}
模版内容
{{- end}}
 
# 去除test模版头部的第一个空行
{{- template "test" }}

Leading spaces for yaml file syntax:

# 这种方式定义的模版,会去除test模版头部和尾部所有的空行
{{- define "test" -}}
模版内容
{{- end -}}
 
# 可以在test模版每一行的头部增加4个空格,用于yaml文件的对齐
{{ include "test" | indent 4}}

Create your own chart

We created a chart called the mongodb, take a look at the file structure chart

$ helm create mongodb
$ tree mongodb
mongodb
├── Chart.yaml #Chart本身的版本和配置信息
├── charts #依赖的chart
├── templates #配置模板目录
│   ├── NOTES.txt #helm提示信息
│   ├── _helpers.tpl #用于修改kubernetes objcet配置的模板 │ ├── deployment.yaml #kubernetes Deployment object │ └── service.yaml #kubernetes Serivce └── values.yaml #kubernetes object configuration 2 directories, 6 files

template

Under Templates directory is yaml template file, follow Go template syntax. Used Hugo static website generation tools should be familiar with this.

We view the contents deployment.yaml file.

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 }}

This is yaml Deployment of the application profile, wherein the portion of the curly brackets bag is expanded up Go template, which is defined in the values.yaml Values ​​file:

# 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

Mirror image such as a container as defined in the Deployment.yaml: "{{.Values.image.repository}}: {{.Values.image.tag}}" where:

  • .Values.image.repository is nginx

  • .Values.image.tag is stable

Two or more variable values ​​are generated automatically create chart when the default value

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12355457.html