1705646542815.png

1705646597634.png
1705646616167.png
1705646637785.png
image.png
image.png

helm安装(v3版本)

下载安装包

image.png

解压安装包,并移动到/usr/bin/目录下

tar -zxvf helm-v3.0.0-linux-amd64.tar.gz

cd linux-amd64/

ls


image.png

mv helm /usr/bin/

移动后即可使用

配置helm仓库

(1)添加仓库

helm repo add 仓库名 仓库地址

添加微软仓库

helm repo add stable http://mirror.azure.cn/kubernetes/charts

image.png

查看仓库

helm repo list

image.png

添加阿里云仓库

helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

image.png

查看仓库

helm repo list

image.png

更新仓库

helm repo update

image.png

删除仓库

helm repo remove aliyun

image.png
image.png

使用helm快速部署应用

1.使用命令搜索应用

helm search repo 名称(weave)

image.png

2.根据搜索内容选择安装

helm install 安装之后的名称 搜索之后的应用名称

#例子
helm install ui stable/weave-scope

image.png

3.查看发布状态

helm list
helm status 安装之后的名称

image.png
image.png
查看
image.png
修改service的yaml文件,type改为:NodePort

kubectl edit svc ui-weave-scope

image.png
image.png
image.png
image.png

创建Chart

1.使用命令创建chart

helm create  mychart

image.png
image.png
image.png

  • Chart.yaml:当前chart属性配置信息
  • templates:编写yaml文件放到这个目录中
  • values.yaml:yaml文件可以使用全局变量

2.在templates文件夹创建两个yaml文件

  • deployment.yaml
  • service.yaml
#创建deployment文件,不新建deployment
kubectl create deployment web1 --image=nginx --dry-run -o yaml > deployment.yaml
#创建deployment
kubectl create deployment web1 --image=nginx

image.png
image.png

vim 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文件,不新建service
kubectl expose deployment web1 --port=80 --target-port=80 --type=NodePort --dry-run -o yaml > service.yaml

image.png

vim service.yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: web1
  name: web1
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: web1
  type: NodePort
status:
  loadBalancer: {}

3.安装mychart

#安装mychart
helm install web1 mychart

#删除创建的mychart phoenix-chart 为name ;other 为namespace
helm uninstall phoenix-chart --namespace other

image.png

kubectl get pods

image.png

kubectl get svc

image.png

4.应用升级

helm upgrade web1 mychart/

image.png

实现yaml高效服用

image.png

在value.yaml定义变量和值

cd mychart/
vim value.yaml

image.png

在templates的yaml文件使用value.yaml定义变量

通过表达式形式使用全局变量
{{.Values.变量名称}}

vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: {{.Values.label}}
  name: {{.Release.Name}}-deploy
spec:
  replicas: {{.Values.replicas}}
  selector:
    matchLabels:
      app: {{.Values.label}}
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: {{.Values.label}}
    spec:
      containers:
      - image: {{.Values.image}}
        name: nginx
        resources: {}
status: {}
vim service.yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: {{.Values.label}}
  name: {{.Values.label}}-svc
spec:
  ports:
  - port: {{.Values.port}}
    protocol: TCP
    targetPort: 80
  selector:
    app: {{.Values.label}}
  type: NodePort
status:
  loadBalancer: {}
helm install --dry-run web2 mychart/

image.png
创建

helm install  web2 mychart/

image.png
image.png
image.png

posted on 2024-01-25 17:26  bigdate  阅读(2)  评论(0编辑  收藏  举报