helm系列之-使用helm部署应用

使用helm部署应用

Helm 是一个 Kubernetes 的包管理工具,用于简化应用的部署和管理。下面是用helm在k8s上部署应用的一般流程。

  1. 添加helm仓库
# 添加仓库
root@master1:~# helm repo add aliyun  https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
root@master1:~# helm repo add bitnami https://charts.bitnami.com/bitnami

# 更新
root@master1:~# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "aliyun" chart repository
...Successfully got an update from the "harbor" chart repository
...Successfully got an update from the "gitlab-jh" chart repository
...

# 仓库列表
root@master1:~# helm repo list
NAME            URL
ingress-nginx   https://kubernetes.github.io/ingress-nginx
openebs         https://openebs.github.io/openebs
harbor          https://helm.goharbor.io
jenkins         https://charts.jenkins.io
gitlab          https://charts.gitlab.io/
gitlab-jh       https://charts.gitlab.cn
bitnami         https://charts.bitnami.com/bitnami
aliyun          https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

# 删除
helm repo remove xxx
  1. 搜索应用
root@master1:~# helm search repo nginx
NAME                                    CHART VERSION   APP VERSION     DESCRIPTION
aliyun/nginx-ingress                    0.9.5           0.10.2          An nginx Ingress controller that uses ConfigMap...
aliyun/nginx-lego                       0.3.1                           Chart for nginx-ingress-controller and kube-lego
bitnami/nginx                           18.1.4          1.27.0          NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller        11.3.12         1.11.0          NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel                     2.1.15          0.4.9           DEPRECATED NGINX Open Source for Intel is a lig...
ingress-nginx/ingress-nginx             4.11.0          1.11.0          Ingress controller for Kubernetes using NGINX a...
aliyun/gcloud-endpoints                 0.1.0                           Develop, deploy, protect and monitor your APIs ...

默认情况下可以直接部署官方发布的chart,也可以下拉取到本地后进行修改。

  1. 修改chart
# 拉取chart
root@master1:~# helm pull bitnami/nginx --version 18.1.4

# 解压缩chart
root@master1:~# tar xf nginx-18.1.4.tgz
root@master1:~# cd nginx/
root@master1:~/nginx# ls
Chart.lock  charts  Chart.yaml  README.md  templates  values.schema.json  values.yaml
root@master1:~/nginx# vim values.yaml

global:
  imageRegistry: "harbor.test.com"  # 改为私有的helm仓库,此处为本地的harbor服务器
  ## E.g.
  ## imagePullSecrets:
  ##   - myRegistryKeySecretName
...
image:
  registry: docker.io
  repository: bitnami/nginx
  tag: 1.27.0-debian-12-r3    # 根据本地harbor仓库的nginx镜像,修改repository和tag。registry可以不用修改,使用global配置。
  digest: ""
  ## Specify a imagePullPolicy

...
service:
  ## @param service.type Service type
  ##
  type: LoadBalancer  # 默认为LoadBalancer,如果没有LB可以修改为NodePort或ClusterIP等。
  ## @param service.ports.http Service HTTP port
  ## @param service.ports.https Service HTTPS port
  ##
  ports:

备注

  1. Helm chart 通常包含一个 values.yaml 文件,用于配置应用的参数。
  2. 也可以使用 --values 参数指定一个自定义的 values.yaml 文件。
  3. 也可以通过 --set 参数在命令行中设置参数:

helm install my-nginx stable/nginx --set service.type=LoadBalancer

  1. 将nginx镜像下载后推送到本地harbor仓库
# 从docker hub下载nginx镜像
nerdctl pull bitnami/nginx:1.27.0-debian-12-r3

# 重新打tag推送到本地的harbor
nerdctl tag bitnami/nginx:1.27.0-debian-12-r3 harbor.test.com/bitnami/nginx:1.27.0-debian-12-r3
# 推送之前需要在harbor上创建bitnami的项目
nerdctl push harbor.test.com/bitnami/nginx:1.27.0-debian-12-r3
  1. 此时部署chart,镜像默认会从本地的harbor去拉取
root@master1:~/nginx/nginx# ls
Chart.lock  charts  Chart.yaml  README.md  templates  values.schema.json  values.yaml

root@master1:~/nginx/nginx# helm install webapp .
root@master1:~/nginx/nginx# helm status webapp
  1. 检查部署的nginx
root@master1:~/nginx/nginx# kubectl get pod
NAME                              READY   STATUS    RESTARTS       AGE
webapp-nginx-7958699dc-45stm      1/1     Running   0              10m
root@master1:~/nginx/nginx# kubectl get svc
NAME             TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)                      AGE
kubernetes       ClusterIP      10.96.0.1     <none>          443/TCP                      21d
webapp-nginx     LoadBalancer   10.98.11.69   192.168.0.242   80:32079/TCP,443:32506/TCP   17m

本文使用的环境有LB,访问http://192.168.0.242即可看到nginx页面。

  1. 升级部署的应用

helm upgrade webapp . --values values.yaml

  1. 删除部署的应用

helm uninstall webapp

默认为default,删除指定命名空间需要指定-n <ns-name>

相关推荐

  1. helm系列-使用helm部署应用

    2024-07-14 21:52:01       20 阅读
  2. helm系列-构建自己的Helm Chart

    2024-07-14 21:52:01       23 阅读
  3. 使用helm部署 redis 单机版

    2024-07-14 21:52:01       48 阅读
  4. 【DevOps】掌握 Helm:Kubernetes 应用程序部署指南

    2024-07-14 21:52:01       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 21:52:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 21:52:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 21:52:01       58 阅读
  4. Python语言-面向对象

    2024-07-14 21:52:01       69 阅读

热门阅读

  1. A. Only Pluses

    2024-07-14 21:52:01       19 阅读
  2. 质量小议40 -- 合格

    2024-07-14 21:52:01       21 阅读
  3. IOS热门面试题(二)

    2024-07-14 21:52:01       20 阅读
  4. KVM-QEMU

    KVM-QEMU

    2024-07-14 21:52:01      13 阅读
  5. Linux重要知识点

    2024-07-14 21:52:01       17 阅读