kong在kubernetes中的安裝及使用

  • 使用helm安裝node

  • 下載適合的helm example https://github.com/Kong/charts/tree/main/charts/kong/example-valuesgit

  • 本次下載github

wget https://raw.githubusercontent.com/Kong/charts/main/charts/kong/example-values/minimal-kong-standalone.yaml

-參考修改後配置 minimal-kong-standalone.yamlsql

image:
  repository: kong
  tag: "2.3"

env:
  prefix: /kong_prefix/
  database: postgres

admin:
  enabled: true
  # 修改ClusterIP,外網不能訪問
  type: ClusterIP
  http:
    enabled: true
    servicePort: 8001
    containerPort: 8001

# 私有k8s。導出 NodePort
proxy:
  type: NodePort
  http:
    nodePort: 30002
  tls:
    nodePort: 30000

postgresql:
  enabled: true
  persistence:
    storageClass: rook-cephfs
    accessModes:
    - ReadWriteMany
  postgresqlUsername: kong
  postgresqlDatabase: kong
  # 固定密碼,不隨機
  postgresqlPassword: Kong.=2021!
  postgresqlPostgresPassword: Kong.=2021!
  service:
    port: 5432

ingressController:
  enabled: true
  installCRDs: false

  • 安裝kong
# 安裝到默認default空間
helm install kong kong/kong -f minimal-kong-standalone.yaml
helm upgrade kong kong/kong -f minimal-kong-standalone.yaml

  • 安裝konga。konga是UI庫,調用kong-admin來管理kong https://github.com/pantsel/konga
apiVersion: apps/v1
kind: Deployment
metadata:
  name: konga
  labels:
    app: konga
spec:
  replicas: 1
  selector:
    matchLabels:
      app: konga
  template:
    metadata:
      labels:
        app: konga
    spec:
      containers:
      - env:
        - name: DB_ADAPTER
          value: postgres
        - name: DB_URI
          # kong-postgresql爲service name
          value: "postgresql://kong:Kong.=2021!@kong-postgresql:5432/konga_database"
        image: pantsel/konga
        imagePullPolicy: Always
        name: konga
        ports:
        - containerPort: 1337
          protocol: TCP
      restartPolicy: Always

---
apiVersion: v1
kind: Service
metadata:
  name: konga
spec:
  ports:
  - name: http
    port: 1337
    targetPort: 1337
    protocol: TCP
  selector:
    app: konga

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: konga-ingress
  annotations:
    kubernetes.io/ingress.class: kong
spec:
  rules:
  - host: konga.your_domain.com
    http:
      paths:
      - path: /
        pathType: ImplementationSpecific
        backend:
          service:
            name: konga
            port:
              number: 1337

  • konga運行後效果

  • kong的prometheus監控。首先在konga中啓用prometheus
  • 安裝prometheus的ServiceMonitor。prometheus安裝參考 https://my.oschina.net/u/160697/blog/3197715
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: prometheus-kong
  # 需固定release: prometheus。默認建立的prometheus使用此標籤來識別
  labels:
    release: prometheus
spec:
  # 不在同一命名空間,加上namespaceSelector
  namespaceSelector:
    matchNames:
    - default
  # 匹配的service的標籤
  selector:
    matchLabels:
      app.kubernetes.io/name: kong
  endpoints:
  # service中對應的端口名稱
  - port: kong-admin
相關文章
相關標籤/搜索