部署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
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐