kubernetes(29):k8s包管理工具-helm(3)-完整样例
helm总结篇:完整样例
https://www.cnblogs.com/tylerzhou/p/11136107.html
通过一个完整的示例总结 Helm 创建、打包、分发、安装、升级及回退Kubernetes应用。
1 创建一个名为mychart的chart
[root@k8s-master helm]# helm create mychart
Creating mychart
2 Mychart配置文件说明
[root@k8s-master helm]# tree mychart mychart ├── charts #该目录中放置当前Chart依赖的其它Chart ├── Chart.yaml # Chart本身的版本和配置信息 ├── templates #模板文件目录 │ ├── deployment.yaml #deployment文件 │ ├── _helpers.tpl #用于修改kubernetes objcet配置的模板 │ ├── ingress.yaml #ingress文件 │ ├── NOTES.txt #helm提示信息 │ ├── service.yaml#service文件 │ └── tests │ └── test-connection.yaml └── values.yaml #用于存储 templates 目录中模板文件中用到变量的值。 3 directories, 8 files [root@k8s-master helm]#
Chart.yaml 用于描述这个 Chart的相关信息,包括名字、描述信息以及版本等。
values.yaml 用于存储 templates 目录中模板文件中用到变量的值。
NOTES.txt 用于介绍 Chart 部署后的一些信息,例如:如何使用这个 Chart、列出缺省的设置等。
Templates 目录下是 YAML 文件的模板,该模板文件遵循 Go template 语法。
Templates 目录下 YAML 文件模板的值默认都是在 values.yaml 里定义的,比如在deployment.yaml 中定义的容器镜像。
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
其中的 .Values.image.repository 的值就是在 values.yaml 里定义的 nginx,.Values.image.tag 的值就是 stable。这个在之前文章写过不在赘述。
[root@k8s-master helm]# cat mychart/values.yaml | grep repository repository: nginx [root@k8s-master helm]# cat mychart/values.yaml | grep tag tag: stable [root@k8s-master helm]#
以上两个变量值是在 create chart 的时候就自动生成的默认值,你可以根据实际情况进行修改。
如果你需要了解更多关于 Go 模板的相关信息,可以查看 Hugo 的一个关于 Go 模板 的介绍。
3 编写应用的介绍信息Chart.yaml
打开 Chart.yaml, 填写你部署的应用的详细信息
# cat Chart.yaml apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes name: mychart version: 0.1.0 [root@k8s-master mychart]#
4 编写具体应用部署信息values.yaml
我们先全部使用默认的
# cat values.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 nameOverride: "" fullnameOverride: "" service: type: ClusterIP port: 80 ingress: enabled: false annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: - host: chart-example.local paths: [] 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: {} [root@k8s-master mychart]#
5 检查依赖和模板配置是否正确
[root@k8s-master helm]# helm lint mychart ==> Linting mychart [INFO] Chart.yaml: icon is recommended 1 chart(s) linted, no failures [root@k8s-master helm]#
如果文件格式错误,可以根据提示进行修改。
也可以使用helm install --dry-run --debug <chart_dir>命令来验证chart配置。该输出中包含了模板的变量配置与最终渲染的yaml文件。
[root@k8s-master helm]# helm install --dry-run --debug mychart [debug] Created tunnel using local port: '37143' [debug] SERVER: "127.0.0.1:37143" [debug] Original chart version: "" [debug] CHART PATH: /root/helm/mychart NAME: wizened-tortoise REVISION: 1 RELEASED: Wed Sep 25 11:55:55 2019 CHART: mychart-0.1.0 USER-SUPPLIED VALUES: {} COMPUTED VALUES: affinity: {} fullnameOverride: "" image: pullPolicy: IfNotPresent repository: nginx tag: stable ingress: annotations: {} enabled: false hosts: - host: chart-example.local paths: [] tls: [] nameOverride: "" nodeSelector: {} replicaCount: 1 resources: {} service: port: 80 type: ClusterIP tolerations: [] HOOKS: --- # wizened-tortoise-mychart-test-connection apiVersion: v1 kind: Pod metadata: name: "wizened-tortoise-mychart-test-connection" labels: app.kubernetes.io/name: mychart helm.sh/chart: mychart-0.1.0 app.kubernetes.io/instance: wizened-tortoise app.kubernetes.io/managed-by: Tiller annotations: "helm.sh/hook": test-success spec: containers: - name: wget image: busybox command: ['wget'] args: ['wizened-tortoise-mychart:80'] restartPolicy: Never MANIFEST: --- # Source: mychart/templates/service.yaml apiVersion: v1 kind: Service metadata: name: wizened-tortoise-mychart labels: app.kubernetes.io/name: mychart helm.sh/chart: mychart-0.1.0 app.kubernetes.io/instance: wizened-tortoise app.kubernetes.io/managed-by: Tiller spec: type: ClusterIP ports: - port: 80 targetPort: http protocol: TCP name: http selector: app.kubernetes.io/name: mychart app.kubernetes.io/instance: wizened-tortoise --- # Source: mychart/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: wizened-tortoise-mychart labels: app.kubernetes.io/name: mychart helm.sh/chart: mychart-0.1.0 app.kubernetes.io/instance: wizened-tortoise app.kubernetes.io/managed-by: Tiller spec: replicas: 1 selector: matchLabels: app.kubernetes.io/name: mychart app.kubernetes.io/instance: wizened-tortoise template: metadata: labels: app.kubernetes.io/name: mychart app.kubernetes.io/instance: wizened-tortoise spec: containers: - name: mychart image: "nginx:stable" imagePullPolicy: IfNotPresent ports: - name: http containerPort: 80 protocol: TCP livenessProbe: httpGet: path: / port: http readinessProbe: httpGet: path: / port: http resources: {}
我们可以看到Deployment和Service的名字前半截由两个随机的单词组成,最后才是我们在values.yaml中配置的值。
6 将应用打包
当然可以不用打包直接helm install 目录部署
[root@k8s-master helm]# helm package mychart Successfully packaged chart and saved it to: /root/helm/mychart-0.1.0.tgz [root@k8s-master helm]#
mychart 目录会被打包为一个 mychart-0.1.0.tgz 格式的压缩包,该压缩包会被放到当前目录下,并同时被保存到了 Helm 的本地缺省仓库目录中。
如果你想看到更详细的输出,可以加上 --debug 参数来查看打包的输出,输出内容应该类似如下:
[root@k8s-master helm]# helm package mychart --debug Successfully packaged chart and saved it to: /root/helm/mychart-0.1.0.tgz [debug] Successfully saved /root/helm/mychart-0.1.0.tgz to /root/.helm/repository/local [root@k8s-master helm]#
7 将应用发布到 Repository
新版本中执行 helm init 命令后默认会配置一个名为 local 的本地仓库。通过helm repo list 可以看到local选项
如果本地repository没启动,可以用下面命令启动
helm serve & 或者helm serve --address 192.168.100.211:8879 &
[root@k8s-master helm]# helm repo list NAME URL stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts local http://127.0.0.1:8879/charts [root@k8s-master helm]# [root@k8s-master helm]# helm search mychart NAME CHART VERSION APP VERSION DESCRIPTION local/mychart 0.1.0 1.0 A Helm chart for Kubernetes [root@k8s-master helm]#
如果需要部署repository
$ helm serve & Now serving you on 127.0.0.1:8879
默认情况下该服务只监听 127.0.0.1,如果你要绑定到其它网络接口,可使用以下命令:
helm serve --address 192.168.100.211:8879 &
如果你想使用指定目录来做为 Helm Repository 的存储目录,可以加上 --repo-path 参数
helm serve --address 192.168.124.59:8879 --repo-path /data/helm/repository/ --url http://192.168.124.59:8879/charts/
通过 helm repo index 命令将 Chart 的 Metadata 记录更新在 index.yaml 文件中:
更新 Helm Repository 的索引文件
cd /home/k8s/.helm/repository/local helm repo index --url=http://192.168.100.211:8879 .
完成启动本地 Helm Repository Server 后,就可以将本地 Repository 加入 Helm 的 Repo 列表
$ helm repo add local http://127.0.0.1:8879 "local" has been added to your repositories
现在再次查找 mychart 包,就可以搜索到了。
$ helm repo update $ helm search mychart NAME CHART VERSION APP VERSION DESCRIPTION local/mychart 0.1.0 1.0 A Helm chart for Kubernetes
8 部署chart到k8s集群中
Chart 被发布到仓储后,就可以通过 helm install 命令部署该 Chart
- 检查配置和模板是否有效
当使用 helm install
命令部署应用时,实际上就是将 templates 目录下的模板文件渲染成 Kubernetes 能够识别的 YAML 格式。
在部署前我们可以使用 helm install --dry-run --debug --name 命令来验证 Chart 的配置。该输出中包含了模板的变量配置与最终渲染的 YAML 文件。
helm install --dry-run --debug local/mychart --name wx-mychart-test
部署时可以指定也可以不指定名称,不指定就随机啦
[root@k8s-master helm]# helm install local/mychart NAME: ornery-camel LAST DEPLOYED: Wed Sep 25 12:20:37 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME READY UP-TO-DATE AVAILABLE AGE ornery-camel-mychart 0/1 1 0 1s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE ornery-camel-mychart-d9b4dfb86-pgr8j 0/1 ContainerCreating 0 1s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ornery-camel-mychart ClusterIP 10.100.209.3 <none> 80/TCP 1s NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mychart,app.kubernetes.io/instance=ornery-camel"-o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:80 [root@k8s-master helm]# helm ls NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE ornery-camel 1 Wed Sep 25 12:20:37 2019 DEPLOYED mychart-0.1.0 1.0 default [root@k8s-master helm]# helm install local/mychart --name wx-test NAME: wx-test LAST DEPLOYED: Wed Sep 25 12:20:50 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME READY UP-TO-DATE AVAILABLE AGE wx-test-mychart 0/1 1 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE wx-test-mychart-574dd6f4b6-xsqgz 0/1 ContainerCreating 0 0s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE wx-test-mychart ClusterIP 10.97.28.121 <none> 80/TCP 0s NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mychart,app.kubernetes.io/instance=wx-test" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:80 [root@k8s-master helm]# helm ls NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE ornery-camel 1 Wed Sep 25 12:20:37 2019 DEPLOYED mychart-0.1.0 1.0 default wx-test 1 Wed Sep 25 12:20:50 2019 DEPLOYED mychart-0.1.0 1.0 default [root@k8s-master helm]#
9 验证部署结果
[root@k8s-master helm]# kubectl get pod,svc | grep wx-test pod/wx-test-mychart-574dd6f4b6-xsqgz 1/1 Running 0 3m59s service/wx-test-mychart ClusterIP 10.97.28.121 <none> 80/TCP 3m59s [root@k8s-master helm]# curl -I 10.97.28.121 HTTP/1.1 200 OK Server: nginx/1.16.1 Date: Wed, 25 Sep 2019 04:24:55 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 13 Aug 2019 10:05:00 GMT Connection: keep-alive ETag: "5d528b4c-264" Accept-Ranges: bytes
10 文件升级
我们修改一下Nginx版本,最新版本 是1.16.1,我们v2版本用1.15.1
# cat values.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: 1.15.1 pullPolicy: IfNotPresent nameOverride: "" fullnameOverride: "" …
k8s-master mychart]# helm upgrade -f values.yaml wx-test local/mychart Release "wx-test" has been upgraded. Happy Helming! LAST DEPLOYED: Wed Sep 25 12:36:33 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME READY UP-TO-DATE AVAILABLE AGE wx-test-mychart 1/1 1 1 15m ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE wx-test-mychart-574dd6f4b6-xsqgz 1/1 Running 0 15m wx-test-mychart-84d867df45-4sghh 0/1 ContainerCreating 0 0s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE wx-test-mychart ClusterIP 10.97.28.121 <none> 80/TCP 15m NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mychart,app.kubernetes.io/instance=wx-test" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:80 [root@k8s-master mychart]# kubectl get pod,svc|grep wx-test pod/wx-test-mychart-574dd6f4b6-xsqgz 1/1 Running 0 16m pod/wx-test-mychart-84d867df45-4sghh 0/1 ContainerCreating 0 20s service/wx-test-mychart ClusterIP 10.97.28.121 <none> 80/TCP 16m [root@k8s-master mychart]# [root@k8s-master helm]# kubectl get pod,svc| grep wx-test pod/wx-test-mychart-84d867df45-4sghh 1/1 Running 0 69s service/wx-test-mychart ClusterIP 10.97.28.121 <none> 80/TCP 16m
我们能看到mychart升级的过程
升级成功
[root@k8s-master helm]# curl -I 10.97.28.121 HTTP/1.1 200 OK Server: nginx/1.15.1 Date: Wed, 25 Sep 2019 04:39:16 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 03 Jul 2018 13:27:08 GMT Connection: keep-alive ETag: "5b3b79ac-264" Accept-Ranges: bytes
11 提交仓库
我们发现虽然部署的chart已经是2版本,但是本地仓库还是1版本,需要提交一下
[root@k8s-master helm]# helm history wx-test REVISION UPDATED STATUS CHART DESCRIPTION 1 Wed Sep 25 12:20:50 2019 SUPERSEDED mychart-0.1.0 Install complete 2 Wed Sep 25 12:36:33 2019 DEPLOYED mychart-0.1.0 Upgrade complete [root@k8s-master helm]# helm list wx-test NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE wx-test 2 Wed Sep 25 12:36:33 2019 DEPLOYED mychart-0.1.0 1.0 default [root@k8s-master helm]# helm search mychart NAME CHART VERSION APP VERSION DESCRIPTION local/mychart 0.1.0 1.0 A Helm chart for Kubernetes [root@k8s-master helm]# [root@k8s-master helm]# vim mychart/Chart.yaml [root@k8s-master helm]# cat mychart/Chart.yaml apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes name: mychart version: 0.2.0 [root@k8s-master helm]# helm package mychart Successfully packaged chart and saved it to: /root/helm/mychart-0.2.0.tgz [root@k8s-master helm]# helm search mychart NAME CHART VERSION APP VERSION DESCRIPTION local/mychart 0.2.0 1.0 A Helm chart for Kubernetes [root@k8s-master helm]#
12 先创建包再升级
文件升级容易遗忘仓库版本,不如先创建好chart包,根据chart包升级
我们调整版本,再把service的类型改成NodePort
[root@k8s-master helm]# vim mychart/Chart.yaml [root@k8s-master helm]# vim mychart/values.yaml [root@k8s-master helm]# cat mychart/Chart.yaml apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes name: mychart version: 0.3.0 [root@k8s-master helm]# cat mychart/values.yaml | grep type type: NodePort [root@k8s-master helm]# [root@k8s-master helm]# helm package mychart Successfully packaged chart and saved it to: /root/helm/mychart-0.3.0.tgz [root@k8s-master helm]# helm search mychart NAME CHART VERSION APP VERSION DESCRIPTION local/mychart 0.3.0 1.0 A Helm chart for Kubernetes [root@k8s-master helm]# [root@k8s-master helm]# helm install local/mychart --name wx-test NAME: wx-test LAST DEPLOYED: Wed Sep 25 13:48:33 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME READY UP-TO-DATE AVAILABLE AGE wx-test-mychart 0/1 1 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE wx-test-mychart-84d867df45-wg8xl 0/1 ContainerCreating 0 0s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE wx-test-mychart NodePort 10.103.191.236 <none> 80:31188/TCP 0s NOTES: 1. Get the application URL by running these commands: export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services wx-test-mychart) export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT [root@k8s-master helm]# kubectl get pod,svc| grep wx-test pod/wx-test-mychart-84d867df45-wg8xl 1/1 Running 0 6s service/wx-test-mychart NodePort 10.103.191.236 <none> 80:31188/TCP 6s [root@k8s-master helm]#
13 根据应用名和历史记录回滚
[root@k8s-master helm]# helm history wx-test REVISION UPDATED STATUS CHART DESCRIPTION 1 Wed Sep 25 13:48:33 2019 SUPERSEDED mychart-0.3.0 Install complete 2 Wed Sep 25 13:49:42 2019 SUPERSEDED mychart-0.3.0 Upgrade complete 3 Wed Sep 25 13:49:49 2019 SUPERSEDED mychart-0.3.0 Upgrade complete 4 Wed Sep 25 13:52:11 2019 SUPERSEDED mychart-0.4.0 Upgrade complete 5 Wed Sep 25 13:52:16 2019 SUPERSEDED mychart-0.4.0 Upgrade complete 6 Wed Sep 25 13:54:49 2019 SUPERSEDED mychart-0.5.0 Upgrade complete 7 Wed Sep 25 13:55:22 2019 DEPLOYED mychart-0.4.0 Rollback to 4 [root@k8s-master helm]# helm list NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE wx-test 7 Wed Sep 25 13:55:22 2019 DEPLOYED mychart-0.4.0 1.0 default [root@k8s-master helm]# [root@k8s-master helm]# helm rollback wx-test 2 Rollback was a success! Happy Helming! [root@k8s-master helm]# kubectl get pod,svc| grep wx-test pod/wx-test-mychart-84d867df45-mfqxp 0/1 Running 0 4s pod/wx-test-mychart-ddb8b4b5f-mb5qc 1/1 Running 0 4m10s service/wx-test-mychart NodePort 10.103.191.236 <none> 80:31188/TCP 7m47s [root@k8s-master helm]# [root@k8s-master helm]# kubectl get pod,svc| grep wx-test pod/wx-test-mychart-84d867df45-mfqxp 1/1 Running 0 17s pod/wx-test-mychart-ddb8b4b5f-mb5qc 0/1 Terminating 0 4m23s service/wx-test-mychart NodePort 10.103.191.236 <none> 80:31188/TCP 8m [root@k8s-master helm]# [root@k8s-master helm]# [root@k8s-master helm]# [root@k8s-master helm]# kubectl get pod,svc| grep wx-test pod/wx-test-mychart-84d867df45-mfqxp 1/1 Running 0 25s service/wx-test-mychart NodePort 10.103.191.236 <none> 80:31188/TCP 8m8s [root@k8s-master helm]# curl -I 10.103.191.236 HTTP/1.1 200 OK Server: nginx/1.15.1 Date: Wed, 25 Sep 2019 05:56:47 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 03 Jul 2018 13:27:08 GMT Connection: keep-alive ETag: "5b3b79ac-264" Accept-Ranges: bytes [root@k8s-master helm]#
14 发布chart指定版本
例如我都晕了发的第几版了,我还是按chart版本包发布吧。
我现在是第3版本,我想发布第一版本,当然可以回滚发布,也可--version指定版本号
[root@k8s-master helm]# helm list NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE wx-test 8 Wed Sep 25 13:56:17 2019 DEPLOYED mychart-0.3.0 1.0 default [root@k8s-master helm]# helm search mychart -l NAME CHART VERSION APP VERSION DESCRIPTION local/mychart 0.5.0 1.0 A Helm chart for Kubernetes local/mychart 0.4.0 1.0 A Helm chart for Kubernetes local/mychart 0.3.0 1.0 A Helm chart for Kubernetes local/mychart 0.1.0 1.0 A Helm chart for Kubernetes [root@k8s-master helm]# helm upgrade wx-test local/mychart --version 0.1.0 Release "wx-test" has been upgraded. Happy Helming! LAST DEPLOYED: Wed Sep 25 14:03:48 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME READY UP-TO-DATE AVAILABLE AGE wx-test-mychart 1/1 1 1 15m ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE wx-test-mychart-84d867df45-mskbc 0/1 ContainerCreating 0 1s wx-test-mychart-ddb8b4b5f-p9hgt 1/1 Running 0 108s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE wx-test-mychart NodePort 10.103.191.236 <none> 80:31188/TCP 15m NOTES: 1. Get the application URL by running these commands: export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services wx-test-mychart) export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT [root@k8s-master helm]# kubectl get pod,svc| grep wx pod/wx-test-mychart-84d867df45-mskbc 1/1 Running 0 84s service/wx-test-mychart NodePort 10.103.191.236 <none> 80:31188/TCP 16m [root@k8s-master helm]# curl -I 10.103.191.236 HTTP/1.1 200 OK Server: nginx/1.15.1 Date: Wed, 25 Sep 2019 06:05:16 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 03 Jul 2018 13:27:08 GMT Connection: keep-alive ETag: "5b3b79ac-264" Accept-Ranges: bytes [root@k8s-master helm]# [root@k8s-master helm]# helm list NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE wx-test 10 Wed Sep 25 14:03:48 2019 DEPLOYED mychart-0.1.0 1.0 default [root@k8s-master helm]#
15 部署到指定命名空间
helm install 默认情况下是部署在 default 这个命名空间的。如果想部署到指定的命令空间,可以加上 --namespace 参数,比如:
[root@k8s-master helm]# helm install --name wx-test2 local/mychart --namespace=kube-system NAME: wx-test2 LAST DEPLOYED: Wed Sep 25 14:29:36 2019 NAMESPACE: kube-system STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME READY UP-TO-DATE AVAILABLE AGE wx-test2-mychart 0/1 1 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE wx-test2-mychart-7cc8b85c9c-plkbq 0/1 ContainerCreating 0 0s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE wx-test2-mychart NodePort 10.102.195.166 <none> 80:31623/TCP 0s NOTES: 1. Get the application URL by running these commands: export NODE_PORT=$(kubectl get --namespace kube-system -o jsonpath="{.spec.ports[0].nodePort}" services wx-test2-mychart) export NODE_IP=$(kubectl get nodes --namespace kube-system -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT [root@k8s-master helm]# [root@k8s-master helm]# helm list NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE wx-test 1 Wed Sep 25 14:26:08 2019 DEPLOYED mychart-0.5.0 1.0 default wx-test2 1 Wed Sep 25 14:29:36 2019 DEPLOYED mychart-0.5.0 1.0 kube-system [root@k8s-master helm]#
16 查看应用部署状态
[root@k8s-master helm]# helm status wx-test LAST DEPLOYED: Wed Sep 25 14:26:08 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME READY UP-TO-DATE AVAILABLE AGE wx-test-mychart 1/1 1 1 4m58s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE wx-test-mychart-ddb8b4b5f-ppvtf 1/1 Running 0 4m58s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE wx-test-mychart NodePort 10.97.100.83 <none> 80:32496/TCP 4m58s NOTES: 1. Get the application URL by running these commands: export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services wx-test-mychart) export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT [root@k8s-master helm]#
17 查看应用部署详细信息
[root@k8s-master helm]# helm get wx-test REVISION: 1 RELEASED: Wed Sep 25 14:26:08 2019 CHART: mychart-0.5.0 USER-SUPPLIED VALUES: {} COMPUTED VALUES: affinity: {} fullnameOverride: "" image: ……
18 删除一个应用
[root@k8s-master helm]# helm delete wx-test release "wx-test" deleted [root@k8s-master helm]#
确认应用是否删除,该应用已被标记为 DELETED 状态。
[root@k8s-master helm]# helm list --deleted NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE wx-test 10 Wed Sep 25 14:03:48 2019 DELETED mychart-0.1.0 1.0 default [root@k8s-master helm]# helm list --all NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE wx-test 10 Wed Sep 25 14:03:48 2019 DELETED mychart-0.1.0 1.0 default [root@k8s-master helm]#
彻底删除指定 Release 所有相关的 Kubernetes 资源和 Release 的历史记录
[root@k8s-master helm]# helm del wx-test --purge release "wx-test" deleted [root@k8s-master helm]# helm list --all [root@k8s-master helm]#
19 删除repository本地仓库的软件包或者chart
不知道有没有命令行可以实现,是不是只能通过harbor这种版本库实现呢?
[root@k8s-master ~]# cd ~/.helm/repository/ [root@k8s-master repository]# ls cache local repositories.yaml [root@k8s-master repository]# cd local/ [root@k8s-master local]# ls hello-helm-0.1.0.tgz index.yaml mychart-0.1.0.tgz mychart-0.3.0.tgz mychart-0.4.0.tgz mychart-0.5.0.tgz [root@k8s-master local]#