1. 程式人生 > 其它 >阿里雲kubernetes上搭建Yapi服務

阿里雲kubernetes上搭建Yapi服務

報錯(1):MongoNetworkError: Authentication failed., mongodb Authentication failed

解決方法: 如果確認了客戶端或者命令列都能了連線mongodb,但是yapi連線卻報錯的話,那麼authSource 不能預設寫admin,要改成空串就可以了

- name:YAPI_DB_AUTH_SOURCE value:"" 參考:http://t.zoukankan.com/sddai-p-13807310.html

報錯(2): 配置完了ldap卻說找不到使用者

若要用郵件作為賬號,則YAPI_LDAP_LOGIN_SEARCH_STANDARD=mail即可,而且最後三項非必填,如果不確定就都不寫了

參考:YAPI工具配置LDAP統一使用者認證 - ouhy - 部落格園 (cnblogs.com)

(3)最後貼上完整的yaml檔案:

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    app: yapi-pod
  namespace: public-service
  name: yapi-deployment
spec:
  selector:
    matchLabels:
      app: yapi-pod
  template:
    metadata:
      labels:
        app: yapi-pod
    spec:
      restartPolicy: Always
      containers:
        #yapi
        - image: jayfong/yapi:1.10.2
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
          name: yapi
          env:
            #管理員賬號,禁止註冊,預設密碼: ymfe.org 登入請修改
            - name: YAPI_ADMIN_ACCOUNT
              value: "[email protected]"
            - name: YAPI_ADMIN_PASSWORD
              value: "123456"
            - name: YAPI_CLOSE_REGISTER
              value: "true"
            #mongodb 配置
            - name: YAPI_DB_SERVERNAME
              value: "dds123456.mongodb.rds.aliyuncs.com"
            - name: YAPI_DB_PORT
              value: "27017"
            - name: YAPI_DB_DATABASE
              value: "yapi"
            - name: YAPI_DB_USER
              value: "yapi"
            - name: YAPI_DB_PASS
              value: "123456"
            - name: YAPI_DB_AUTH_SOURCE
              value: ""
            #mail 郵件功能
            - name: YAPI_MAIL_ENABLE
              value: "true"
            - name: YAPI_MAIL_HOST
              value: "smtp.exmail.qq.com"
            - name: YAPI_MAIL_PORT
              value: "465"
            - name: YAPI_MAIL_FROM
              value: "[email protected]"
            - name: YAPI_MAIL_AUTH_USER
              value: "[email protected]"
            - name: YAPI_MAIL_AUTH_PASS
              value: "123456"
            #ldap 功能
            - name: YAPI_LDAP_LOGIN_ENABLE
              value: "true"
            - name: YAPI_LDAP_LOGIN_SERVER
              value: "ldap://ldap-service.kube-system.svc.cluster.local:389"  #這裡使用的是內網poddns來找到ldap服務
            - name: YAPI_LDAP_LOGIN_BASE_DN
              value: "cn=admin,dc=example,dc=com"
            - name: YAPI_LDAP_LOGIN_BIND_PASSWORD
              value: "123456"
            - name: YAPI_LDAP_LOGIN_SEARCH_DN
              value: "dc=example,dc=com"
            - name: YAPI_LDAP_LOGIN_SEARCH_STANDARD  #若要用郵件作為賬號,則YAPI_LDAP_LOGIN_SEARCH_STANDARD=mail即可
              value: "mail"
---
apiVersion: v1
kind: Service
metadata:
  name: yapi-service
  namespace: public-service
spec:
  selector:
    app: yapi-pod
  ports:
  - name: yapi-port
    protocol: TCP
    port: 8080
    targetPort: 3000
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: yapi-ingress
  namespace: public-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    nginx.ingress.kubernetes.io/connection-proxy-header: "keep-alive"
    nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
    nginx.ingress.kubernetes.io/proxy-body-size: 80m
spec:
  tls:
  - hosts:
    - 'www.xxxx.com'
    secretName: xxx-com-secret   #https的證書  這裡可以參考我的另外一篇Kubernetes Ingress配置HTTPS
  rules:
  - host: www.xxxx.com
    http:
      paths:
      - path: /
        backend:
          serviceName: yapi-service
          servicePort: 8080

參考:

https://github.com/fjc0k/docker-YApi

https://www.icode9.com/content-4-1069439.html

https://www.leeguangxing.cn/blog_post_92.html

https://blog.csdn.net/weixin_45444133/article/details/118673418

http://t.zoukankan.com/sddai-p-13807310.html

https://blog.csdn.net/weixin_45444133/article/details/118673418