hyperf helm
时间: 2023-09-10 17:13:37 浏览: 53
Helm 是 Kubernetes 的一个包管理工具,它可以帮助我们更方便地部署和管理 Kubernetes 应用程序。使用 Helm 部署 Hyperf 应用程序,可以方便地管理应用程序的依赖关系、配置文件和部署版本等信息。
要使用 Helm 部署 Hyperf 应用程序,需要先创建一个 Helm Chart,定义应用程序的依赖关系、配置文件和部署信息等。可以使用 `helm create` 命令创建一个默认的 Helm Chart,然后在该 Chart 的 `templates` 目录下创建一个名为 `hyperf.yaml` 的清单文件。
下面是一个简单的 Hyperf Helm Chart 的示例:
```
my-hyperf/
Chart.yaml
values.yaml
templates/
_helpers.tpl
deployment.yaml
service.yaml
hyperf.yaml
```
`Chart.yaml` 文件定义了 Chart 的基本信息,例如 Chart 的名称、版本号和描述等。`values.yaml` 文件定义了 Chart 的默认配置信息。`templates` 目录下的文件则定义了 Kubernetes 资源的清单文件。
在 `hyperf.yaml` 文件中,我们可以定义 Hyperf 应用程序的 Deployment 和 Service 资源。例如:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "my-hyperf.fullname" . }}
labels:
{{- include "my-hyperf.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "my-hyperf.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "my-hyperf.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: hyperf
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
ports:
- name: http
containerPort: 9501
env:
- name: APP_NAME
value: {{ .Values.appName }}
- name: ENVIRONMENT
value: {{ .Values.environment }}
{{- toYaml .Values.env | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{- toYaml .Values.volumeMounts | nindent 12 }}
{{- toYaml .Values.pod | nindent 8 }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "my-hyperf.fullname" . }}-svc
labels:
{{- include "my-hyperf.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "my-hyperf.selectorLabels" . | nindent 4 }}
```
在 `values.yaml` 文件中,我们可以定义应用程序的默认配置信息。例如:
```yaml
appName: my-hyperf-app
environment: production
replicaCount: 3
image:
repository: my-docker-registry/hyperf-app
tag: latest
env:
- name: DB_HOST
value: mysql
- name: DB_PORT
value: "3306"
- name: DB_USERNAME
value: root
- name: DB_PASSWORD
value: password
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 500m
memory: 1Gi
volumeMounts:
- name: config
mountPath: /hyperf/config
podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/path: "/metrics"
service:
type: NodePort
port: 80
```
最后,可以使用 `helm install` 命令来安装 Hyperf 应用程序:
```
helm install my-hyperf ./my-hyperf
```
这将会使用 `my-hyperf` 目录下的 Helm Chart 来安装 Hyperf 应用程序。可以使用 `helm upgrade` 命令来更新应用程序的配置或版本号等信息。