1、部署pv对应的yaml文件

cat pv.yaml 
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: tomcat-data
spec:
  capacity:
    storage: 5Gi 
  accessModes:
  - ReadWriteMany 
  nfs: 
    path: /app/tomcat_data
    server: 192.168.1.88
  persistentVolumeReclaimPolicy: Recycle 

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: tomcat-data
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi

2、创建pv

kubectl create -f pv.yaml

3、创建deployment的yaml文件

cat deploy.yml 
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: tomcat-dev
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: tomcat-dev
    spec:
      containers:
      - name: tomcat-dev
        image: tomcat:latest
        imagePullPolicy: IfNotPresent
        ports:
        - name: web
          containerPort: 8080
        volumeMounts:
        - mountPath: /usr/local/tomcat/webapps
          name: tomcat-data
      volumes:
      - name: tomcat-data
        persistentVolumeClaim:
          claimName: tomcat-data
---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-dev
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30001
  selector:
    name: tomcat-dev

4、创建deploy

kubectl create -f deploy.yml 
Logo

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

更多推荐