kubernetes部署yapi

一,yapi

因为之前开发使用postman(不是企业版),在很多时候不能统一接口,并更好交付给前端和其他人员,所以打算部署一套yapi

对比了一些需求,发下yapi符合大部分常用功能,所以选择。

文档:https://hellosean1025.github.io/yapi/

 

二、编写tke-storageClass.yaml

使用tke-storageclasses进行持久化存储

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  # annotations:
  #   storageclass.beta.kubernetes.io/is-default-class: "true"
  #   如果有这一条,则会成为 default-class,创建 PVC 时不指定类型则自动使用此类型
  name: cloud-mongo
provisioner: cloud.tencent.com/qcloud-cbs ## TKE 集群自带的 provisioner
parameters:
  type: CLOUD_PREMIUM
  # 支持 CLOUD_BASIC,CLOUD_PREMIUM,CLOUD_SSD  如果不识别则当做 CLOUD_BASIC
  paymode: PREPAID
  # paymode为云盘的计费模式,PREPAID模式(包年包月:仅支持Retain保留的回收策略),默认是 POSTPAID(按量计费:支持 Retain 保留和 Delete 删除策略,Retain 仅在高于1.8的集群版本生效)
  # aspid:asp-123
  # 支持指定快照策略,创建云盘后自动绑定此快照策略,绑定失败不影响创建
reclaimPolicy: Retain

创建tke-storageClass.yaml

kubectl create -f tke-storageClass.yaml

 

三、编写mongo.yaml

使用tke-storageclasses进行持久化存储

apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    app: mongo
spec:
  ports:
    - port: 27017
      targetPort: 27017
      name: mongo
  selector:
    app: mongo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo
  labels:
    app: mongo
spec:
  serviceName: mongo
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  template:
    metadata:
      labels:
        app: mongo
    spec:
      imagePullSecrets:
      - name: registry-pull-secret
      containers:
        - name: mongo
          image: ccr.ccs.tencentyun.com/lvvimage/mongo:latest
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 500m
              memory: 1024Mi
            requests:
              cpu: 200m
              memory: 512Mi
          env:
          - name: TZ
            value: Asia/Shanghai
          ports:
          - name: mongo
            containerPort: 27017
            protocol: TCP
          volumeMounts:
          - name: mongo-pvc
            mountPath: /data/db
  volumeClaimTemplates:  # 自动创建pvc,进而自动创建pv
  - metadata:
      name: mongo-pvc
    spec:
      accessModes: [ "ReadWriteMany" ]
      storageClassName: cloud-mongo
      resources:
        requests:
          storage: 100Gi

创建mongo.yaml

kubectl create -f mongo.yaml 

 

四、编写yapi.yaml

env内的值可根据实际需要更改

apiVersion: v1
kind: Service
metadata:
  name: yapi
  labels:
    app: yapi
spec:
  ports:
    - port: 32368
      targetPort: 32368
      name: yapi
      nodePort: 32368
  type: NodePort
  selector:
    app: yapi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: yapi
  labels:
    app: yapi
spec:
  replicas: 1
  selector:
    matchLabels:
      app: yapi
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: yapi
    spec:
      imagePullSecrets:
      - name: registry-pull-secret
      containers:
        - name: yapi
          image: ccr.ccs.tencentyun.com/lvvimage/yapi:latest
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 500m
              memory: 1024Mi
            requests:
              cpu: 200m
              memory: 512Mi
          env:
          - name: TZ
            value: Asia/Shanghai
          - name: VERSION
            value: 1.8.0
          - name: LOG_PATH
            value: /tmp/yapi.log
          - name: HOME
            value: /home
          - name: PORT
            value: "32368"
          - name: ADMIN_EMAIL
            value: [email protected]
          - name: DB_SERVER
            value: mongo
          - name: DB_NAME
            value: yapi
          - name: DB_PORT
            value: "27017"
          ports:
          - name: yapi
            containerPort: 32368
            protocol: TCP

创建yapi.yaml

kubectl create -f yapi.yaml

 

五、访问yapi

kubectl get svc | grep yapi

访问地址:http://IP:NodePort

kubernetes部署yapi_第1张图片

 

你可能感兴趣的:(kubernetes部署yapi)