k8s部署postgresql
文件中的信息,然后应用YAML文件。文件中的信息,然后应用YAML文件。文件中的信息,然后应用YAML文件。
·
部署pvc
修改postgresql-pvc.yaml
文件中的信息,然后应用YAML文件
cat > /opt/k8s/postgresql/postgresql-pvc.yaml <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgresql-data-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: "nfs-storage"
resources:
requests:
storage: 5Gi
EOF
kubectl apply -f postgresql-pvc.yaml
kubectl get pvc
部署Deployment
修改postgresql-Deployment.yaml
文件中的信息,然后应用YAML文件
cat > /opt/k8s/postgresql/postgresql-Deployment.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgresql-deployment
spec:
replicas: 1
selector:
matchLabels:
app: postgresql
template:
metadata:
labels:
app: postgresql
spec:
containers:
- name: postgresql
image: postgres:11.7
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: "postgresql"
- name: POSTGRES_PASSWORD
value: "postgresql"
- name: POSTGRES_DB
value: postgres # 数据库名
- name: TZ
value: Asia/Shanghai
- name: POSTGRES_MAX_CONNECTIONS
value: "20000"
- name: PGDATA
value: "/var/lib/postgresql/data/pgdata"
volumeMounts:
- mountPath: "/var/lib/postgresql/data/"
name: postgresql-storage
volumes:
- name: postgresql-storage
persistentVolumeClaim:
claimName: postgresql-data-pvc
EOF
kubectl apply -f postgresql-Deployment.yaml
kubectl get Deployment
部署Service
修改postgresql-Service.yaml
文件中的信息,然后应用YAML文件
cat > /opt/k8s/postgresql/postgresql-Service.yaml <<EOF
apiVersion: v1
kind: Service
metadata:
name: postgresql-service
spec:
type: NodePort
ports:
- port: 5432
targetPort: 5432
nodePort: 30032
selector:
app: postgresql
EOF
kubectl apply -f postgresql-Service.yaml
kubectl get Service
更多推荐
已为社区贡献6条内容
所有评论(0)