侧边栏壁纸
博主头像
小周的知识站 博主等级

行动起来,活在当下

  • 累计撰写 80 篇文章
  • 累计创建 12 个标签
  • 累计收到 8 条评论

目 录CONTENT

文章目录

Chart包开发—1

Administrator
2024-12-07 / 0 评论 / 0 点赞 / 33 阅读 / 0 字

1 Chart 目录结构

[root@master ~]# helm pull stable/mysql

[root@master ~]# tar xf mysql-1.6.8.tgz

[root@master ~]# ls mysql
Chart.yaml  README.md  templates  values.yaml

[root@master ~]# ls -l mysql/templates/ 
total 48
-rwxr-xr-x 1 root root  292 Jan  1  1970 configurationFiles-configmap.yaml
-rwxr-xr-x 1 root root 8930 Jan  1  1970 deployment.yaml
-rwxr-xr-x 1 root root 1290 Jan  1  1970 _helpers.tpl
-rwxr-xr-x 1 root root  295 Jan  1  1970 initializationFiles-configmap.yaml
-rwxr-xr-x 1 root root 2036 Jan  1  1970 NOTES.txt
-rwxr-xr-x 1 root root  868 Jan  1  1970 pvc.yaml
-rwxr-xr-x 1 root root 1475 Jan  1  1970 secrets.yaml
-rwxr-xr-x 1 root root  328 Jan  1  1970 serviceaccount.yaml
-rwxr-xr-x 1 root root  800 Jan  1  1970 servicemonitor.yaml
-rwxr-xr-x 1 root root 1231 Jan  1  1970 svc.yaml
drwxr-xr-x 2 root root   50 Nov 13 18:43 tests

文件

说明

Chart.yaml

用于描述Chart的基本信息; helm show chart stable/mysql命令查看的内容就是此文件内容

values.yaml

Chart的默认配置文件; helm show values stable/mysql命令查看的内容就是此文件内容

README.md

[可选] 当前Chart的介绍

LICENS

[可选] 协议

requirements.yaml

[可选] 用于存放当前Chart依赖的其它Chart的说明文件

charts/

[可选]: 该目录中放置当前Chart依赖的其它Chart

templates/

[可选]: 部署文件模版目录

2 创建不可配置的chart

2.1 创建目录与chart.yaml

[root@k8s-master01 ~]# mkdir -p /helm/nginx/templates
[root@k8s-master01 ~]# cd  /helm/nginx

2.2 创建deployment.yaml

[root@k8s-master01 nginx]# vim templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helm-nginx
spec:
  replicas: 1                                   
  selector:
    matchLabels:
      app: helm-nginx
  template:
    metadata:
      labels:
        app: helm-nginx
    spec:
      containers:
      - name: c1
        image: nginx:1.15-alpine
        imagePullPolicy: IfNotPresent

2.3 创建service.yaml

[root@k8s-master01 nginx]# vim templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: helm-nginx
spec:
  selector:
    app: helm-nginx
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP

2.4 使用chart安装应用

[root@k8s-master01 nginx]# helm install /helm/nginx --generate-name
NAME: nginx-1659144826
LAST DEPLOYED: Sat Jul 30 09:33:46 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

2.5 查看与验证

[root@k8s-master01 nginx]# helm ls
NAME                    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
nginx-1659144826        default         1               2022-07-30 09:33:46.881083524 +0800 CST deployed        helm-nginx-1.0.0

[root@k8s-master01 nginx]# kubectl get pods,service
NAME                                         READY   STATUS    RESTARTS      AGE
pod/helm-nginx-65f57fb758-nrpvf              1/1     Running   0             51s
pod/nfs-client-provisioner-9d46587b5-7n2vf   1/1     Running   4 (31m ago)   42h

NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
service/helm-nginx   ClusterIP   10.96.2.120   <none>        80/TCP    51s

[root@k8s-master01 nginx]# curl http://10.96.2.120
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

2.5 删除

[root@k8s-master01 ~]# helm uninstall nginx-1659144826
release "nginx-1659144826" uninstalled

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区