K8s helm 创建自定义Chart

# 删除之前创建的 chart
helm list
helm delete --purge redis1

# 创建自定义 chart myapp
cd ~/helm
helm create myapp

cd myapp/

tree ./
./
├── charts                          # 目录用于存放所依赖的子chart
├── Chart.yaml                      # 描述这个 Chart 的相关信息、包括名字、描述信息、版本等
├── templates                       # 模板目录,通常会使用values.yaml配置内容进行填充,板引擎渲染此目录的文件后Tiller将渲染得到的结果 提交给Kubernetes创建响应的对象
│   ├── deployment.yaml             # deployment 控制器的 Go 模板文件
│   ├── _helpers.tpl                # 模板助手文件,定义的值可在模板中使用
│   ├── ingress.yaml                # ingress 的模板文件 
│   ├── NOTES.txt                   # Chart 部署到集群后的一些信息,例如:如何使用、列出缺省值
│   ├── serviceaccount.yaml
│   ├── service.yaml                # service 的 Go 模板文件
│   └── tests
│       └── test-connection.yaml
└── values.yaml                     # 模板的值文件,这些值会在安装时应用到 GO 模板生成部署文件


# 修改 Chart.yaml
cat Chart.yaml

apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes myapp chart
name: myapp
version: 0.0.1
maintainer:
- name: klvchen
  email: klvchen@126.com
  url: http://www.klvchen.com


# 修改 values.yaml
cat values.yaml 

# Default values for myapp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 2

image:
  repository: ikubernetes/myapp
  tag: v1
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80
  targetPort: 80

ingress:
  enabled: false
  annotations: 
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "true"
  path: /
  hosts:
    - chart-example.local
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resources: 
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

# 测试打包
cd ..
helm lint ./myapp
helm package myapp/

# 创建代理,注意这里需要在 myapp-0.0.1.tgz  同级上执行,这里会启动一个web服务,端口为 8879
helm serve

# 新开一个终端,安装
helm install --name myapp1 local/myapp

# 测试,访问 ClusterIP
curl 10.102.91.53
#运行结果,正常:
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>

# 查看 myapp1 的状态
helm status myapp1

原文地址:https://www.cnblogs.com/klvchen/p/10096666.html