文章目录

ConfigMap

#(这里我们只写了confmap的形式)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        resources:
          requests:
            memory: 50Mi
            cpu: 500m
        securityContext:
          privileged: true
        volumeMounts:           #(这里基于supath的形式去不覆盖其他目录的形式mounpath就是覆盖整个目录)  
        - name: nginx-conf             
          mountPath: /usr/share/nginx/html/index.html
          subPath: usr/share/nginx/html/index.html  #(subpath 这里的形式就是这样的)
      volumes:
        - name: nginx-conf
          configMap:
            name: nginx-conf
            items:
            - key: index.html
              path: usr/share/nginx/html/index.html #(#subpath 这里的形式就是这样的)

Pv

1、这里我创建的是静态的pv+pvc
2、confmap 我这里定义的是nginx html页面

[root@k8s-master02 nginxpv+mount]# cat nginx.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: nginx-test
spec:
  selector:
    matchLabels:
      app: nginx-test
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx-test
    spec:
      containers:
      - name: nginx-test
        image: registry.harbor.com/test/nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: index
          mountPath: /usr/share/nginx/html
        - name: nginx    #自己定义的名字引用下面的(自己定义的名字)
          mountPath: /root   #挂载到容器里面的目录
      volumes:
      - name: index
        configMap:
          name: index
          items:
            - key: index.html
              path: index.html
      - name: nginx      #自己定义的名字
        persistentVolumeClaim:    #引用的模式
          claimName: pvc15      #引用到的pvc
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-test
spec:
  type: NodePort
  ports:
  - port: 80
  selector:
    app: nginx-test
Logo

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

更多推荐