helm和chart

Helm

helm是Kubernetes 应用的包管理工具,主要用来管理 Charts,类似Linux系统的yum。Helm Chart 是用来封装 Kubernetes 原生应用程序的一系列 YAML 文件。可以在你部署应用的时候自定义应用程序的一些 Metadata,以便于应用程序的分发。

helm安装完成后一下设置可以自动补齐
echo "source <(helm completion bash)" >> ~/.bashrc   %设置命令补齐
source ~/.bashrc    %使之生效

helm search hub搜索官方chart库

创建chart
helm create nginx-test
在这里插入图片描述
Chart.yaml 中定义了:
chart的name和helm create nginx-test名字保持一致
helm的版本信息
chart的版本信息
发布的应用的版本信息
也可以添加maintainers等

values.yaml中定义了需要的变量值,如果有需要可以再添加

_helpers.tpl : 中定义了一些模板可以在deployment或者ingress等模板中应用

NOTES.txt中显示了在部署完成后的一些提示

deployment.yaml中的 - include “nginx-test.labels” . | nindent 4
-是消除空白行,include是引用_helpers.tpl中定义的模板 nindent 是缩进
resources:
{ {- toYaml .Values.resources | nindent 12 }}
toYaml是指将values中的值通过yaml格式展现

如果有configmap的需求可参考以下:
新建一个etc/目录,将配置文件放到etc下

**default.conf**
server {
   listen       80;
   server_name  localhost;

   location / {
       root   /usr/share/nginx/html;
       index  index.html index.htm;
   }

   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
       root   /usr/share/nginx/html;
   }
}

**values.yaml**
image:
 repository: nginx
 tag: latest

configurationFiles:
 conf:
   data:
     nginx.conf: |-
       {
   
   { .Files.Get "config/nginx.conf" | nindent 8 }}

**deployment.yaml中引用**
containers:
 - name: nginx
   image: "{
   
   { .Values.image.repository }}:{
   
   { .Values.image.tag }}"
   volumeMounts:
     - name: nginx-config
       mountPath: /etc/nginx/conf.d/default.conf
       subPath: default.conf
volumes:
 - name: nginx-config
   configMap:
     name: {
   
   { include "mychart.fullname" . }}-conf

猜你喜欢

转载自blog.csdn.net/qq_39412605/article/details/130501954