apiVersion: apps/v1 kind: Deployment metadata: name: nfs-deployment-python spec: replicas: 2 selector: matchLabels: app: python-nfs template: metadata: labels: app: python-nfs spec: containers: - name: python-nfs image: python:3.8.2 imagePullPolicy: IfNotPresent command: ['/bin/bash', '-c', '--'] # 启动"python -m http.server 80"服务,“>>”表示向文件中追加数据 args: ['echo "

The host is $(hostname)

" >> /containerdata/podinfor; python -m http.server 80'] # 设置80端口 ports: - name: http containerPort: 80 # 设置挂载点 volumeMounts: # 此处的名称与volumes有对应关系 - name: python-nfs-data mountPath: /containerdata # 配置nfs存储卷 volumes: # 此处的名称需与spec.containers.volumeMounts.name相同 - name: python-nfs-data # 向PVC申请资源,此处的名称对应# nfs-pvc.yaml文件中的metadata.name persistentVolumeClaim: claimName: nfs-pvc