温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

charts使用方法与Repo仓库的创建

发布时间:2020-05-25 17:35:16 来源:亿速云 阅读:315 作者:鸽子 栏目:云计算

1、开发自己的chare包

[root@master ~]# helm create mychare
//创建一个名为mychare的chare包
[root@master ~]# tree -C mychare/
//以树状图查看一下chare包
mychare/
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

2、调试chart

[root@master mychare]# cd
[root@master ~]# helm install --dry-run --debug mychare
//检查这个mychare是否有问题

3、安装chart

[root@node02 ~]# docker pull nginx:stable

(1)通过仓库安装

[root@master mychare]# helm search redis
//搜索chare包
[root@master mychare]# helm repo list
//查看是否有能访问仓库

charts使用方法与Repo仓库的创建

[root@master mychare]# helm install stable/redis
//安装

(2)通过tar包安装

[root@master ~]# helm fetch stable/redis
//直接下载chare包
[root@master ~]# tar -zxf redis-1.1.15.tgz
//解压下载的chare包
[root@master ~]# tree -C redis
redis
├── Chart.yaml
├── README.md
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── networkpolicy.yaml
│   ├── NOTES.txt
│   ├── pvc.yaml
│   ├── secrets.yaml
│   └── svc.yaml
└── values.yaml

(3)通过chare本地目录安装

[root@master ~]# helm fetch stable/redis
//直接下载chare包
[root@master ~]# tar -zxf redis-1.1.15.tgz
//解压下载的chare包
[root@master ~]# helm install redis

(4)通过URL安装

[root@master ~]# helm install https://example.com/charts/foo-1.2.3.tgz

创建自己的Repo仓库

1)创建helm的私有仓库,以自己的名字命名。

1、node01启动一个httpd的容器

[root@node01 ~]# mkdir /var/xgp
//创建一个目录
[root@node01 ~]# docker pull httpd
//下载httpd镜像
[root@node02 ~]# docker run -d -p 8080:80 -v /var/xgp:/usr/local/apache2/htdocs httpd
//启动一个httpd的容器

3、生成仓库的index文件。

[root@master ~]# mkdir xgprepo
//创建一个目录存放打包的chare
[root@master ~]# helm repo index xgprepo/ --url http://192.168.1.22:8080/charts
//生成仓库的index文件

4、将生成的index.yaml上传到node01的/var/www/charts目录下.

node01创建目录
[root@node01 ~]# mkdir /var/xgp/charts
master移动动到
[root@master ~]# scp xgprepo/* node01:/var/xgp/charts/
node01查看一下
[root@node01 ~]# ls /var/xgp/charts/
index.yaml  

5、添加新的repo仓库

[root@master ~]# helm repo add xgp http://192.168.1.22:8080/charts
[root@master ~]# helm repo list 

charts使用方法与Repo仓库的创建

2) 自定义一个chart包,要求这个包运行一个httpd的服务,使用私有镜像v1版本。3个副本Pod,service类型更改为NodePort,端口指定为:30000

自定义一个chart包
[root@master ~]# helm create wsd
//创建一个名为wsd的chares包
按照要求修改配置文件
[root@master ~]# cd wsd/
//进入这个chart包
[root@master wsd]# vim values.yaml
//修改wsd的配置文件
replicaCount: 3                         #三个副本

image:
  repository: 192.168.1.21:5000/web      #更改镜像为私有镜像
  tag: v1                                #镜像标签v1
  pullPolicy: IfNotPresent              

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

service:
  type: NodePort              #修改模式为映射端口
  port: 80
  nodePort: 30000             #添加端口

[root@master wsd]# vim templates/service.yaml 

apiVersion: v1
kind: Service
metadata:
  name: {{ include "wsd.fullname" . }}
  labels:
{{ include "wsd.labels" . | indent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
      nodePort: {{ .Values.service.nodePort }}    #“添加”能让服务识别到nodePort的端口
  selector:
    app.kubernetes.io/name: {{ include "wsd.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
测试一下
[root@master ~]# helm install -n wsd  wsd/ -f wsd/values.yaml 

charts使用方法与Repo仓库的创建

查看一下镜像版本
[root@master ~]# kubectl get deployments. -o wide

charts使用方法与Repo仓库的创建

访问一下
[root@master ~]# curl 127.0.0.1:30000

charts使用方法与Repo仓库的创建

3)  将实例进行更新,要求镜像生产v2版本。

私有镜像和官方镜像升级有所不同,官方的只需通过 (helm upgrade --set imageTag=“标签” 服务名称 charts包名 )进行更改标签即可,而私有镜像需通过更改values.yaml中的标签才行比较麻烦一点。

1、修改values.yaml

[root@master ~]# vim wsd/values.yaml 

# Default values for wsd.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 3

image:
  repository: 192.168.1.21:5000/web
  tag: v2                            #修改标签为v2
  pullPolicy: IfNotPresent
[root@master ~]# helm upgrade wsd wsd/ -f wsd/values.yaml
//基于配置文件刷新一下wsd服务
查看一下
[root@master ~]# kubectl get deployments. -o wide

charts使用方法与Repo仓库的创建

访问一下
[root@master ~]# curl 127.0.0.1:30000

charts使用方法与Repo仓库的创建

2、使用edit进行版本更新

确定wsd这个服务开启

[root@master ~]# kubectl edit deployments. wsd

charts使用方法与Repo仓库的创建

查看一下
[root@master ~]# kubectl get deployments. -o wide

charts使用方法与Repo仓库的创建

访问一下
[root@master ~]# curl 127.0.0.1:30000

charts使用方法与Repo仓库的创建

4)重新定义一个chart包,名称为: new-test,将这个包上传到上述私有仓库中,需要用helm repo update命玲更新本地的index文件。

[root@master ~]# helm repo list 

charts使用方法与Repo仓库的创建

[root@master ~]# helm create xgp-wsd
//创建一个名为xgp-wsd的charts包

[root@master ~]# helm package xgp-wsd/
//将xgp-wsd打包在当前目录

[root@master ~]# mv xgp-wsd-0.1.0.tgz xgprepo/
//把打包文件放到仓库目录

[root@master ~]# helm repo index xgprepo/ --url http://192.168.1.22:8080/charts
//把仓库目录新加入的charts包信息记录在index.yaml中,使得其他加入的主机可以识别到,仓库的charts包

[root@master ~]# scp xgprepo/* node01:/var/xgp/charts
//将仓库目录的文件移动到httpd服务上,使各个主机可以访问,下载仓库的charts包

[root@master ~]# helm repo update 
//更新一下chart存储库

[root@master myrepo]# helm install http://192.168.1.22:8080/charts/xgp-wsd-0.1.0.tgz
//基于仓库的xgp-wsd-0.1.0.tgz包创建一个服务

查看一下

[root@master ~]# helm search xgp-wsd

charts使用方法与Repo仓库的创建

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI