k8s使用local pv部署tomcat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s使用local pv部署tomcat相关的知识,希望对你有一定的参考价值。

参考技术A kind: StorageClass

apiVersion: storage.k8s.io/v1

metadata:

  name: local-storage

provisioner: kubernetes.io/no-provisioner

volumeBindingMode: WaitForFirstConsumer # 设置延迟绑定

# Supported policies: Delete, Reta

# reclaimPolicy: Retain # 删除pvc时保留pv 需要手动删除pv

apiVersion: v1

kind: PersistentVolume

metadata:

  name: local-pv

  labels:

    kafka: kafka

spec:

  capacity:

    storage: 10Gi

  volumeMode: Filesystem

  accessModes:

  - ReadWriteOnce

  persistentVolumeReclaimPolicy: Retain

  storageClassName: local-storage

  local:

    path: /localpv

  nodeAffinity:

    required:

      nodeSelectorTerms:

      - matchExpressions:

        - key: kubernetes.io/hostname

          operator: In

          values:

          - localhost.localdomain

---

kind: PersistentVolumeClaim

apiVersion: v1

metadata:

  name: tomcat-log-tomcat-0

spec:

  accessModes:

  - ReadWriteOnce

  storageClassName: local-storage

  volumeMode: Filesystem

  volumeName: local-pv

  resources:

    requests:

      storage: 1Gi

ps:该文件的PVC_name = volumeClaimTemplates_name(statefulset.yaml中) + "-" + pod_name,不要问我为什么,它就是这个规则

apiVersion: v1

kind: Service

metadata:

  name: tomcat-service

  labels:

    app: tomcat

spec:

  type: NodePort

  ports:

  - port: 8080

    targetPort: 8080

    protocol: TCP

    nodePort: 31080

    name: tomcat-port

  selector:

    app: tomcat

---

apiVersion: apps/v1

kind: StatefulSet

metadata:

  name: tomcat

spec:

  serviceName: "tomcat-service"

  selector:

    matchLabels:

      app: tomcat

  replicas: 2

  template:

    metadata:

      labels:

        app: tomcat

    spec:

      terminationGracePeriodSeconds: 10

      containers:

      - name: tomcat

        image: tomcat:latest

        ports:

        - containerPort: 8080

          name: tomcat-port

        volumeMounts:

        - name: tomcat-log

          mountPath: /usr/local/tomcat/logs

  volumeClaimTemplates:

  - metadata:

      name: tomcat-log

    spec:

      accessModes: [ "ReadWriteOnce" ]

      resources:

        requests:

          storage: 1Gi

最后,全部都执行kubectl apply -f xxxx就行

以上是关于k8s使用local pv部署tomcat的主要内容,如果未能解决你的问题,请参考以下文章

K8S动态PV实战之nginx部署

请教tomcat和jenkins部署的一个问题

k8s 基于NFS部署storageclass pv自动供给

k8s安装nfs设置pv pvc并部署mysql

k8s安装nfs设置pv pvc并部署mysql

k8s存储(部署理论)