Helm应用包管理

Helm介绍

001 Helm是一个Kubernetes的包管理工具
002 就像Linux下的包管理器,如yum/apt等
003 可以很方便的将之前打包好的yaml文件部署到kubernetes上
-----------------------------------------------------------------------------
Helm有3个重要概念:
• helm:一个命令行客户端工具,主要用于Kubernetes应用chart的创建、打包、发布和管理。
• Chart:应用描述,一系列用于描述 k8s 资源相关文件的集合。
• Release:基于Chart的部署实体,一个 chart 被 Helm 运行后将会生成对应的一个 release;将在
k8s中创建出真实运行的资源对象

Helm的安装

[root@k8s-m1 helm]# tar -xzvf helm-v3.4.2-linux-amd64.tar.gz 

[root@k8s-m1 helm]# cd linux-amd64/
[root@k8s-m1 linux-amd64]# ls
helm  LICENSE  README.md
[root@k8s-m1 linux-amd64]# mv helm /usr/bin/

Helm基本使用

Helm的创建与部署

[root@k8s-m1 helm]#  helm create mychart
Creating mychart
[root@k8s-m1 helm]# cd mychart/
[root@k8s-m1 mychart]# ls
charts  Chart.yaml  templates  values.yaml
----------------------------------------------------------------------------------
#values.yaml用于存储 templates 目录中模板文件中用到变量的值。
vi values.yaml 
image:
  repository: nginx
  tag: "1.16"
----------------------------------------------------------------------------------
#安装一个chart
[root@k8s-m1 helm]# helm install web mychart
#列出release
[root@k8s-m1 helm]# helm list 

NAME    NAMESPACE   REVISION        UPDATED    STATUS          CHART           APP VERSION
web     default     1               2021-12-18 deployed        mychart-0.1.0   1.16.0 

----------------------------------------------------------------------------------
#显示已命名版本的状态
[root@k8s-m1 helm]# helm status web
LAST DEPLOYED: Sat Dec 18 15:15:25 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
----------------------------------------------------------------------------------
#查看相关资源
[root@k8s-m1 helm]# kubectl get pod,svc
NAME                               READY   STATUS    RESTARTS   AGE
pod/web-mychart-68cb98d9d8-vwlft   1/1     Running   0          6m38s

NAME                  TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes    ClusterIP   10.0.0.1     <none>        443/TCP   6d1h
service/web-mychart   ClusterIP   10.0.0.123   <none>        80/TCP    6m38s

[root@k8s-m1 helm]# curl -I 10.0.0.123 
HTTP/1.1 200 OK
Server: nginx/1.16.1
----------------------------------------------------------------------------------
#下载一个release。可用子命令:all、hooks、manifest、notes、values
[root@k8s-m1 helm]# helm get all web
......
#查看所有的ymal
[root@k8s-m1 helm]#  helm get manifest  web 
......

Helm的升级

#values,-f:指定YAML文件覆盖值
[root@k8s-m1 helm]# vi values.yaml
image:
  repository: nginx
  tag: "1.17"

[root@k8s-m1 helm]# helm upgrade -f values.yaml web mychart
Release "web" has been upgraded. Happy Helming!
NAME: web
LAST DEPLOYED: Sat Dec 18 15:35:12 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2

[root@k8s-m1 helm]# curl -I 10.0.0.123 
HTTP/1.1 200 OK
Server: nginx/1.17.10

----------------------------------------------------------------------------
#set:在命令行上指定覆盖值
[root@k8s-m1 helm]#  helm upgrade --set image.tag=1.18 web mychart
Release "web" has been upgraded. Happy Helming!
NAME: web
LAST DEPLOYED: Sat Dec 18 15:38:16 2021
NAMESPACE: default
STATUS: deployed
REVISION: 3

[root@k8s-m1 helm]# curl -I 10.0.0.123 
HTTP/1.1 200 OK
Server: nginx/1.18.0

Helm的回滚卸载

#回滚
[root@k8s-m1 helm]# helm history web
REVISION  UPDATED                         STATUS          CHART           APP VERSION   
1        Sat Dec 18    superseded      mychart-0.1.0   1.16.0          Install complete
2        Sat Dec 18    superseded      mychart-0.1.0   1.16.0          Upgrade complete
3        Sat Dec 18    deployed        mychart-0.1.0   1.16.0          Upgrade complete

[root@k8s-m1 helm]# helm rollback web 2
Rollback was a success! Happy Helming!

[root@k8s-m1 helm]# curl -I 10.0.0.123 
HTTP/1.1 200 OK
Server: nginx/1.17.10
----------------------------------------------------------------------------
#卸载
[root@k8s-m1 helm]# helm uninstall web
release "web" uninstalled

自制chart

创建chart

[root@k8s-m1 helm]# mkdir -p chart
[root@k8s-m1 helm]# cd chart
[root@k8s-m1 chart]# mkdir -p templates

Chart.yaml

[root@k8s-m1 chart]# vi Chart.yaml 
apiVersion: v2
name: mychart
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0

values.yaml

[root@k8s-m1 chart]#  vi values.yaml
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"

selectorLabels: "nginx"

deployment.yaml

[root@k8s-m1 templates]# vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx

service.yaml

[root@k8s-m1 templates]# vi service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: web
  name: {{ .Release.Name }}
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: {{ .Values.selectorLabels }}

添加相关文件

[root@k8s-m1 templates]# touch _helpers.tpl
[root@k8s-m1 templates]# touch NOTES.txt
[root@k8s-m1 templates]# vi NOTES.txt 
hello

调试

[root@k8s-m1 helm]# helm install web3 --dry-run chart

MANIFEST:
---
# Source: mychart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: web
  name: web3
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:1.16
        name: nginx

NOTES:
hello

安装部署

[root@k8s-m1 helm]# helm install web3  chart         
NAME: web3
LAST DEPLOYED: Sat Dec 18 16:07:25 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
hello

[root@k8s-m1 helm]# kubectl get pod,svc
NAME                        READY   STATUS    RESTARTS   AGE
pod/web3-6d4cf56db6-zsp22   1/1     Running   0          36s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   6d2h
service/web3         ClusterIP   10.0.0.6     <none>        80/TCP    36s

[root@k8s-m1 helm]# curl -I 10.0.0.6
HTTP/1.1 200 OK
Server: nginx/1.16.1

卸载

[root@k8s-m1 helm]# helm uninstall web3
release "web3" uninstalled

Chart模板

函数与管道

quote:将值转换为字符串

#gpu是boolean,直接取会报错
[root@k8s-m1 chart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"
  
selectorLabels: "nginx"  

nodeSelector:
  gpu: true 
--------------------------------------------------------------------------------
#quote .Values.nodeSelector.gpu
[root@k8s-m1 chart]# vi templates/deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
----------------------------------------------------------------------------------
[root@k8s-m1 chart]#  helm install web1 --dry-run  ../chart

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web1
spec:
  replicas: 
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx

default:设置默认值,如果获取的值为空则为默认值

[root@k8s-m1 chart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"

selectorLabels: "nginx"
nodeSelector:
  gpu: true
labels:
  app: ""
--------------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ .Values.labels.app | default "nginx"  }}
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
        
--------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web2 --dry-run ../chart

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: web2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx
--------------------------------------------------------------------------------
        
[root@k8s-m1 chart]# helm install web2 --set labels.app=abc --dry-run ../chart

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: abc
  name: web2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx

toYaml引用一块YAML内容

#resources
[root@k8s-m1 chart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"

selectorLabels: "nginx"
nodeSelector:
  gpu: true
labels:
  app: nginx

resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests: 
    cpu: 100m
    memory: 128Mi
    
----------------------------------------------------------------------------
#{{ toYaml .Values.resources | nindent 10 }}
[root@k8s-m1 templates]# vi deployment.yaml                       
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ .Values.labels.app | default "nginx"  }}
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
 ---------------------------------------------------------------------------------
 #运行
[root@k8s-m1 chart]# helm install web1 --dry-run ../chart
 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: web1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx
        resources:
          limits:
            cpu: 100m
            memory: 128Mi
          requests:
            cpu: 100m
            memory: 128Mi

流程控制

if/else

[root@k8s-m1 chart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"

selectorLabels: "nginx"
nodeSelector:
  gpu: true
labels:
  app: nginx

resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi

ingress: 
  enabled: true
 -----------------------------------------------------------------------------

[root@k8s-m1 templates]# vi ingress.yaml
{{ if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80
{{ end  }}
-----------------------------------------------------------------------------------
#运行
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
# Source: mychart/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80
------------------------------------------------------------------------------
#判断是否是空的集合
[root@k8s-m1 chart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"
 
selectorLabels: "nginx"
nodeSelector:
  gpu: true
labels:
  app: nginx

resources: {}

ingress:
  enabled: true
  
-------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ .Values.labels.app | default "nginx"  }}
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
        {{- if .Values.image.resources }}
        resources:
          {{ toYaml .Values.resources | nindent 10 }}
        {{- end }}
-------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx

range循环

#遍历数据test  
[root@k8s-m1 chart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"

selectorLabels: "nginx"
nodeSelector:
  gpu: true
labels:
  app: nginx

resources: {}
ingress:
  enabled: true

test:
 - 1
 - 2
 - 3    
-------------------------------------------------------------------------------    
[root@k8s-m1 chart]# vi templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}
data:
  test: |
    {{- range .Values.test }}
      {{ . }}
    {{- end }}    
    
-------------------------------------------------------------------
#运行效果
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: v1
kind: ConfigMap
metadata:
  name: web
data:
  test: |
      1
      2
      3

with

#labels
[root@k8s-master mychart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"
 
selectorLabels: "nginx"
nodeSelector:
  gpu: true
labels:
  app: nginx

resources: {}

ingress:
  enabled: true

test:
 - 1
 - 2
 - 3

labels:
  project: "ms"
  app: "gateway"
  
-------------------------------------------------------------------------------

[root@k8s-m1 chart]# vi templates/deployment.yaml                       
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    {{- with .Values.labels }}
    project: {{ .project }}
    app: {{ .app  }}
    {{- end }}
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
        {{- if .Values.image.resources }}
        resources:
          {{ toYaml .Values.resources | nindent 10 }}
        {{- end }}
        
-------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    project: ms
    app: gateway
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx
-------------------------------------------------------------------------------
#with块限制了变量作用域,也就是无法直接引用模板对象,例如.Values、.Release
#如果还想使用,可以定义变量来解决该问题
[root@k8s-master templates]# vi deployment.yaml                      
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    {{- $rs:= .Values.replicaCount -}}
    {{- with .Values.labels }}
    project: {{ .project }}
    app: {{ .app  }}{{ $rs }}
    {{- end }}
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
        {{- if .Values.image.resources }}
        resources:
          {{ toYaml .Values.resources | nindent 10 }}
        {{- end }}
        
-------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    project: ms
    app: gateway1
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx
        

变量

with、range结合使用

[root@k8s-m1 chart]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "1.16"

selectorLabels: "nginx"
nodeSelector:
  gpu: true
labels:
  app: nginx

resources: {}


ingress:
  enabled: true

test:
 - 1
 - 2
 - 3

labels:
  project: "ms"
  app: "gateway"

env:
  NAME: "gateway"
  JAVA_OPTS: "-Xmx1G"
  
  
-----------------------------------------------------------------------
[root@k8s-master templates]# vi deployment.yaml          
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    {{- $rs:= .Values.replicaCount -}}
    {{- with .Values.labels }}
    project: {{ .project }}
    app: {{ .app  }}{{ $rs }}
    {{- end }}
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
        {{- if .Values.image.resources }}
        resources:
          {{ toYaml .Values.resources | nindent 10 }}
        {{- end }}
        env:
        {{- range $k,$v:= .Values.env }}
          - name: {{ $k }}
            value: {{ $v | quote }}
        {{- end }}        
        
----------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    project: ms
    app: gateway1
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx
        env:
          - name: JAVA_OPTS
            value: "-Xmx1G"
          - name: NAME
            value: "gateway"

#之所以不用toYaml,是因为env是数组方式表示
      

命名模板

#template指令是将一个模板包含在另一个模板中的方法。
#但是,template函数不能用于Go模板管道。
#为了解决该问题,引入include指令。

[root@k8s-m1 chart]# vi templates/_helpers.tpl 
{{- define "fullname" -}}
{{- .Release.Name }}-{{ .Chart.Name }}
{{- end -}}

{{- define "labels" -}}
app: "gateway"
project: "ms"
{{- end}}

------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    {{- include "labels" .| nindent 4}}
  name: {{ template "fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.selectorLabels }}
  strategy: {}
  template:
    metadata:
      labels:
        app: {{ .Values.selectorLabels }}
    spec:
      nodeSelector:
        gpu: {{ quote .Values.nodeSelector.gpu }}
      containers:
      - image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: nginx
        {{- if .Values.image.resources }}
        resources:
          {{ toYaml .Values.resources | nindent 10 }}
        {{- end }}
        env:
        {{- range $k,$v:= .Values.env }}
          - name: {{ $k }}
            value: {{ $v | quote }}
        {{- end }}        
        
-------------------------------------------------------------------------------
 [root@k8s-m1 chart]#  helm install web --dry-run ../chart
 apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: "gateway"
    project: "ms"
  name: web-mychart
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        gpu: "true"
      containers:
      - image: nginx:1.16
        name: nginx
        env:
          - name: JAVA_OPTS
            value: "-Xmx1G"
          - name: NAME
            value: "gateway"

chart的通用

#打包chart
[root@k8s-m1 helm]# helm package chart
Successfully packaged chart and saved it to: /root/helm/mychart-0.1.0.tgz

[root@k8s-m1 demo]# vi values.yaml 
replicaCount: 1

image:
  repository: nginx
  tag: "latest"

service:
  type: ClusterIP
  port: 80
  nodeport: 300001

[root@k8s-m1 demo]# helm install web --set image.tag=1.18 --set service.type=NodePort --set service.nodeport=30010 ../demo

[root@k8s-m1 demo]# kubectl get pod,svc
NAME                            READY   STATUS    RESTARTS   AGE
pod/demo-web-7bbfdb894f-6bpfl   1/1     Running   0          10s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
service/demo-web     NodePort    10.0.0.173   <none>        80:30010/TCP   10s
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP        6d5h

http://192.168.153.25:30010/
----------------------------------------------------------------------------------
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

使用Harbor作为Chart仓库

启用Harbor的Chart仓库服务

[root@harbor harbor]# ./install.sh --with-chartmuseum

安装push插件

[root@k8s-m1 helm]# tar xzvf helm-push_0.9.0_linux_amd64.tar.gz 

[root@k8s-m1 helm]# cd bin/
[root@k8s-m1 bin]# ls
helmpush

[root@k8s-m1 helm]# mkdir -p /root/.local/share/helm/plugins/helm-push

[root@k8s-m1 helm]# mv bin/ plugin.yaml /root/.local/share/helm/plugins/helm-push/

推送

[root@k8s-m1 helm]# helm push demo-0.1.0.tgz --username admin --password Harbor12345 http://192.168.153.20/chartrepo/library
Pushing demo-0.1.0.tgz to http://192.168.153.20/chartrepo/library...
Done.
1639826894687.png

添加repo

[root@k8s-m1 helm]# helm repo add myrepo http://192.168.153.20/chartrepo/library
"myrepo" has been added to your repositories

[root@k8s-m1 helm]# helm repo list
NAME    URL                                    
myrepo  http://192.168.153.20/chartrepo/library

[root@k8s-m1 helm]# helm repo remove myrepo
"myrepo" has been removed from your repositories

部署

[root@k8s-m1 helm]# helm install web3 --version 0.1.0 myrepo/demo

[root@k8s-m1 helm]# helm list
NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
web3    default         1               2021-12-18 19:35:28.887231627 +0800 CST deployed        demo-0.1.0      1.16.0  

[root@k8s-m1 demo]# kubectl get pod,svc
NAME                             READY   STATUS    RESTARTS   AGE
pod/demo-web3-75cc95bdc4-pt5sk   1/1     Running   0          2m5s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/demo-web3    ClusterIP   10.0.0.133   <none>        80/TCP    2m6s
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   6d5h

[root@k8s-m1 demo]# curl -I 10.0.0.133
HTTP/1.1 200 OK
Server: nginx/1.21.4
©著作权归作者所有,转载或内容合作请联系作者
禁止转载,如需转载请通过简信或评论联系作者。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,841评论 5 472
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,415评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,904评论 0 333
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,051评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,055评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,255评论 1 278
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,729评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,377评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,517评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,420评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,467评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,144评论 3 317
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,735评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,812评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,029评论 1 256
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,528评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,126评论 2 341

推荐阅读更多精彩内容