帮我搞一个完完整整的yaml,包括各个部分
时间: 2024-10-16 21:05:02 浏览: 23
yawn-yaml:保留评论和样式的YAML解析器
当然,下面是一个完整的Kubernetes YAML 文件,用于部署Apache Hive 2.1.1,它包含了基本的配置、服务、持久卷及访问MySQL数据库的示例:
```yaml
# 部署文件 (deployment.yaml)
apiVersion: apps/v1
kind: Deployment
metadata:
name: hive-deployment
labels:
app: hive
spec:
replicas: 3 # 设置副本数
selector:
matchLabels:
app: hive
template:
metadata:
labels:
app: hive
spec:
containers:
- name: hive-server
image: apache/hive:2.1.1
ports:
- containerPort: 10000
env:
- name: MYSQL_HOST
value: mysql-service
- name: MYSQL_PORT
value: "3306"
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-secret
key: username
volumeMounts:
- name: data-volume
mountPath: /data
# 数据卷 (persistentvolumeclaim.yaml)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hive-pvc
labels:
app: hive
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi # 请求的存储大小
# 数据卷定义 (pv.yaml)
apiVersion: v1
kind: PersistentVolume
metadata:
name: hive-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
storageClassName: standard # 如果有特定的存储类别,填写这里
hostPath:
path: /path/to/local/directory # 在宿主机上指定数据存放路径
# 服务 (service.yaml)
apiVersion: v1
kind: Service
metadata:
name: hive-service
labels:
app: hive
spec:
selector:
app: hive
ports:
- protocol: TCP
port: 10000
targetPort: 10000
type: ClusterIP # 如果需要外网访问,可以改为NodePort或LoadBalancer
# MySQL连接的Secret (mysql-secret.yaml)
apiVersion: v1
kind: Secret
metadata:
name: mysql-secret
type: Opaque
data:
username: cGFzc3dvcmQ=
password: YWRtaW4=
```
阅读全文