Kubernetes(K8S) helm chart

简介: Kubernetes(K8S) helm chart

感觉和放到一个 yaml 文件中,用 ---- 分隔,操作繁琐程度上,没有太大区别

创建自定义 Chart

# 创建自定义的 chart 名为 mychart
[root@k8smaster ~]# helm create mychart
Creating mychart
[root@k8smaster ~]# cd mychart/
[root@k8smaster mychart]# ls
charts  
Chart.yaml  # 当前chart 属性配置信息
templates   # 编写 yaml 文件放到这个目录,是 yaml 的集合
values.yaml # yaml文件可以使用的全局变量
[root@k8smaster mychart]#

创建 yaml 文件

在 templates 文件夹中创建两个 yaml 文件

  • deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: web1
  name: web1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: web1
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
  • service.yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: web1
  name: web1
spec:
  ports:   
  - port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30390  # 可以指定暴露出去的端口,防止重启 Pod 后发生变化 
  selector:
    app: web1
  type: NodePort
status:
  loadBalancer: {}
# 切换到 templates 目录下
[root@k8smaster mychart]# cd templates/
# 创建一个web1应用--内容见上文
[root@k8smaster templates]# vi deployment.yaml
# 暴露端口--内容见上文
[root@k8smaster templates]# vi service.yaml
[root@k8smaster templates]#

安装

[root@k8smaster ~]# helm install web1 mychart/
NAME: web1
LAST DEPLOYED: Mon Nov 28 14:26:34 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
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=web1" -o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:80
[root@k8smaster ~]# helm list
NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
ui      default         1               2022-11-28 13:15:05.404335352 +0800 CST deployed        weave-scope-1.1.12      1.12.0     
web1    default         1               2022-11-28 14:26:34.854631893 +0800 CST deployed        mychart-0.1.0           1.16.0     
[root@k8smaster ~]# kubectl get pod,svc
NAME                                                READY   STATUS    RESTARTS   AGE
pod/nginx-f89759699-652r4                           1/1     Running   0          5d
pod/nginx-nfs-788564fbc8-g58xd                      1/1     Running   0          5d
pod/weave-scope-agent-ui-7qqd4                      1/1     Running   0          73m
pod/weave-scope-agent-ui-knqwk                      1/1     Running   0          73m
pod/weave-scope-agent-ui-r74cm                      1/1     Running   0          73m
pod/weave-scope-agent-ui-xnrht                      1/1     Running   0          73m
pod/weave-scope-cluster-agent-ui-7498b8d4f4-pmkzh   1/1     Running   0          73m
pod/weave-scope-frontend-ui-649c7dcd5d-jfg72        1/1     Running   0          73m
pod/web1-7f87dfbd56-w7p4d                           1/1     Running   0          91s
NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/javademo1        NodePort    10.106.43.46     <none>        8111:31452/TCP   40d
service/kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP          45d
service/nginx            NodePort    10.103.87.81     <none>        80:30339/TCP     45d
service/nginx-nfs        NodePort    10.99.84.9       <none>        80:30205/TCP     19d
service/ui-weave-scope   NodePort    10.101.4.212     <none>        80:30690/TCP     73m
service/web1             NodePort    10.100.238.141   <none>        80:30390/TCP     91s
[root@k8smaster ~]#

升级

[root@k8smaster ~]# helm upgrade web1 mychart/
Release "web1" has been upgraded. Happy Helming!
NAME: web1
LAST DEPLOYED: Mon Nov 28 14:29:39 2022
NAMESPACE: default
STATUS: deployed
REVISION: 2
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=web1" -o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:80
[root@k8smaster ~]#

yaml 高效复用

通过传递参数,动态渲染模板 yaml 内容,动态传入参数生成

在 chart values.yaml 文件,定义 yaml 文件全局变量

在 values.yaml 定义变量和值

在具体 yaml文件中,获取定义变量的值

  • image、tag、label、port、replicas
定义变量
[root@k8smaster ~]# cd mychart/
[root@k8smaster mychart]# vi values.yaml
image: nginx
replicas: 1
tag: 1.16
label: nginx
port: 80

使用变量

方便统一定义

{{ .Values.变量名称}}

{{ .Release.Name}} -> 获取版本名称

  • deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name}}-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Values.label}}
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: {{ .Values.label}}
    spec:
      containers:
      - image: {{ .Values.image}}
        name: nginx
        resources: {}
status: {}
  • service.yaml
apiVersion: v1
kind: Service
metadata: 
  name: {{ .Release.Name}}-deploy
spec:
  ports:
  - port: {{ .Values.port}}
    protocol: TCP
    targetPort: 80    
  selector:
    app: {{ .Values.label}}
  type: NodePort
status:
  loadBalancer: {}
[root@k8smaster mychart]# vi templates/deployment.yaml 
[root@k8smaster mychart]# vi templates/deployment.yaml 
[root@k8smaster mychart]# cd
[root@k8smaster ~]# helm install --dry-run web2 mychart/
# Source: mychart/templates/service.yaml
apiVersion: v1
kind: Service
metadata: 
  name: web2-deploy
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort
status:
  loadBalancer: {}
---
# Source: mychart/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web2-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
[root@k8smaster ~]# helm install web2 mychart/
NAME: web2
LAST DEPLOYED: Mon Nov 28 15:13:48 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
[root@k8smaster ~]# kubectl get pod,svc 
NAME                                                READY   STATUS    RESTARTS   AGE
pod/nginx-f89759699-652r4                           1/1     Running   0          5d1h
pod/nginx-nfs-788564fbc8-g58xd                      1/1     Running   0          5d1h
pod/weave-scope-agent-ui-7qqd4                      1/1     Running   0          119m
pod/weave-scope-agent-ui-knqwk                      1/1     Running   0          119m
pod/weave-scope-agent-ui-r74cm                      1/1     Running   0          119m
pod/weave-scope-agent-ui-xnrht                      1/1     Running   0          119m
pod/weave-scope-cluster-agent-ui-7498b8d4f4-pmkzh   1/1     Running   0          119m
pod/weave-scope-frontend-ui-649c7dcd5d-jfg72        1/1     Running   0          119m
pod/web1-7f87dfbd56-w7p4d                           1/1     Running   0          47m
pod/web2-deploy-f89759699-9z5n4                     1/1     Running   0          22s
NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/javademo1        NodePort    10.106.43.46     <none>        8111:31452/TCP   40d
service/kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP          45d
service/nginx            NodePort    10.103.87.81     <none>        80:30339/TCP     45d
service/nginx-nfs        NodePort    10.99.84.9       <none>        80:30205/TCP     19d
service/ui-weave-scope   NodePort    10.101.4.212     <none>        80:30690/TCP     119m
service/web1             NodePort    10.100.238.141   <none>        80:30390/TCP     47m
service/web2-deploy      NodePort    10.111.219.124   <none>        80:30277/TCP     22s
[root@k8smaster ~]# helm uninstall web2
release "web2" uninstalled
相关实践学习
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。 &nbsp; &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
目录
相关文章
|
2月前
|
存储 Kubernetes 网络安全
关于阿里云 Kubernetes 容器服务(ACK)添加镜像仓库的快速说明
本文介绍了在中国大陆地区因网络限制无法正常拉取 Docker 镜像的解决方案。作者所在的阿里云 Kubernetes 集群使用的是较旧版本的 containerd(1.2x),且无法直接通过 SSH 修改节点配置,因此采用了一种无需更改 Kubernetes 配置文件的方法。通过为 `docker.io` 添加 containerd 的镜像源,并使用脚本自动修改 containerd 配置文件中的路径错误(将错误的 `cert.d` 改为 `certs.d`),最终实现了通过多个镜像站点拉取镜像。作者还提供了一个可重复运行的脚本,用于动态配置镜像源。虽然该方案能缓解镜像拉取问题,
344 2
|
8月前
|
存储 Kubernetes 监控
K8s集群实战:使用kubeadm和kuboard部署Kubernetes集群
总之,使用kubeadm和kuboard部署K8s集群就像回归童年一样,简单又有趣。不要忘记,技术是为人服务的,用K8s集群操控云端资源,我们不过是想在复杂的世界找寻简单。尽管部署过程可能遇到困难,但朝着简化复杂的目标,我们就能找到意义和乐趣。希望你也能利用这些工具,找到你的乐趣,满足你的需求。
826 33
|
8月前
|
存储 人工智能 Kubernetes
ACK Gateway with AI Extension:面向Kubernetes大模型推理的智能路由实践
本文介绍了如何利用阿里云容器服务ACK推出的ACK Gateway with AI Extension组件,在Kubernetes环境中为大语言模型(LLM)推理服务提供智能路由和负载均衡能力。文章以部署和优化QwQ-32B模型为例,详细展示了从环境准备到性能测试的完整实践过程。
|
10月前
|
存储 运维 Kubernetes
正式开源,Doris Operator 支持高效 Kubernetes 容器化部署方案
飞轮科技推出了 Doris 的 Kubernetes Operator 开源项目(简称:Doris Operator),并捐赠给 Apache 基金会。该工具集成了原生 Kubernetes 资源的复杂管理能力,并融合了 Doris 组件间的分布式协同、用户集群形态的按需定制等经验,为用户提供了一个更简洁、高效、易用的容器化部署方案。
471 16
正式开源,Doris Operator 支持高效 Kubernetes 容器化部署方案
|
9月前
|
监控 Kubernetes Cloud Native
基于阿里云容器服务Kubernetes版(ACK)的微服务架构设计与实践
本文介绍了如何基于阿里云容器服务Kubernetes版(ACK)设计和实现微服务架构。首先概述了微服务架构的优势与挑战,如模块化、可扩展性及技术多样性。接着详细描述了ACK的核心功能,包括集群管理、应用管理、网络与安全、监控与日志等。在设计基于ACK的微服务架构时,需考虑服务拆分、通信、发现与负载均衡、配置管理、监控与日志以及CI/CD等方面。通过一个电商应用案例,展示了用户服务、商品服务、订单服务和支付服务的具体部署步骤。最后总结了ACK为微服务架构提供的强大支持,帮助应对各种挑战,构建高效可靠的云原生应用。
|
9月前
|
弹性计算 人工智能 资源调度
DeepSeek大解读系列公开课上新!阿里云专家主讲云上智能算力、Kubernetes容器服务、DeepSeek私有化部署
智猩猩「DeepSeek大解读」系列公开课第三期即将开讲,聚焦阿里云弹性计算助力大模型训练与部署。三位专家将分别讲解智能算力支撑、Kubernetes容器服务在AI场景的应用实践、以及DeepSeek一键部署和多渠道应用集成,分享云计算如何赋能大模型发展。欲观看直播,可关注【智猩猩GenAI视频号】预约。 (239字符)
|
8月前
|
存储 运维 Kubernetes
容器数据保护:基于容器服务 Kubernetes 版(ACK)备份中心实现K8s存储卷一键备份与恢复
阿里云ACK备份中心提供一站式容器化业务灾备及迁移方案,减少数据丢失风险,确保业务稳定运行。
|
11月前
|
存储 Kubernetes Docker
Kubernetes(k8s)和Docker Compose本质区别
理解它们的区别和各自的优势,有助于选择合适的工具来满足特定的项目需求。
1260 19
|
10月前
|
人工智能 运维 监控
容器服务Kubernetes场景下可观测体系生产级最佳实践
阿里云容器服务团队在2024年继续蝉联Gartner亚洲唯一全球领导者象限,其可观测体系是运维的核心能力之一。该体系涵盖重保运维、大规模集群稳定性、业务异常诊断等场景,特别是在AI和GPU场景下提供了全面的观测解决方案。通过Tracing、Metric和Log等技术,阿里云增强了对容器网络、存储及多集群架构的监控能力,帮助客户实现高效运维和成本优化。未来,结合AI助手,将进一步提升问题定位和解决效率,缩短MTTR,助力构建智能运维体系。
|
11月前
|
Kubernetes 应用服务中间件 nginx
二进制安装Kubernetes(k8s)v1.32.0
本指南提供了一个详细的步骤,用于在Linux系统上通过二进制文件安装Kubernetes(k8s)v1.32.0,支持IPv4+IPv6双栈。具体步骤包括环境准备、系统配置、组件安装和配置等。
3969 11

热门文章

最新文章

推荐镜像

更多