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

使用helm部署应用

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

  1. 添加helm仓库
shell 复制代码
# 添加仓库
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. 搜索应用
shell 复制代码
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
shell 复制代码
# 拉取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仓库
shell 复制代码
# 从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去拉取
shell 复制代码
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
shell 复制代码
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>。

相关推荐
我不会起名字3223 小时前
K8s Ingress 返回 502 但后端日志正常:4 类上游断连与排查链
kubernetes·k8s·ingress·502·keepalive
我不会起名字3228 小时前
Pod 一直 Pending:调度器 5 类失败原因与 kubectl describe 的正确读法
云原生·kubernetes·调度·排查
我不会起名字32210 小时前
K8s 服务 DNS 解析偶发 5 秒超时:conntrack 与 ndots 的 3 个坑
kubernetes·k8s·dns·conntrack·coredns
七夜zippoe14 小时前
把 OpenClaw Agent 搬进 K8s:容器化部署全记录
ai·云原生·容器·kubernetes·openclaw
March.s1 天前
Kubernetes 全景导览:从部署演进到云原生底座
云原生·kubernetes·dubbo
熊出没1 天前
云原生架构落地实践:Kubernetes 生产级配置与 Service Mesh 流量治理
云原生·架构·kubernetes·istio
东风微鸣1 天前
K8s 最佳实践已更新:请使用 Node Swap!
kubernetes
励志师code1 天前
Kubernetes 集群节点生命周期管理实战:从扩容、调度管控到证书续期
运维·docker·容器·kubernetes·gpu算力·kubelet
闲云自留地1 天前
Kubernetes 安装保姆级:关 swap、装 containerd、init 集群、calico 一篇通
容器·贪心算法·kubernetes