前文介绍了在k8s集群内部署API网关kong,在部署完成后,为方便管理kong,通常会再搭配一个面板控制台,本文介绍docker方式和k8s方式部署konga面板

初始化数据库

docker run --rm pantsel/konga:latest \
-c prepare -a postgres -u postgresql://postgres:123456@192.168.1.14:5432/

容器部署

docker run -idt --name=konga -p 1337:1337 \
-e "TOKEN_SECRET=123456" \
-e "DB_ADAPTER=postgres" \
-e "DB_HOST=192.168.1.14" \
-e "DB_PORT=5432" \
-e "DB_USER=postgres" \
-e "DB_PASSWORD=123456" \
-e "DB_DATABASE=konga" \
-e "DB_PG_SCHEMA=public" \
-e "NODE_ENV=production" pantsel/konga

访问测试

k8s部署

  • 此处以华为云CCE容器引擎为例
cat <<EOF | kubectl apply -f  -
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: konga
  name: konga
  namespace: kong
spec:
  replicas: 1
  selector:
    matchLabels:
      app: konga
  template:
    metadata:
      labels:
        app: konga
    spec:
      containers:
      - env:
            - name: DB_ADAPTER
              value: postgres
            - name: DB_HOST
              value: 192.168.223.145
            - name: DB_USER
              value: root
            - name: DB_PASSWORD
              value: xxxxxxxxx
            - name: DB_DATABASE
              value: konga
            - name: DB_PORT
              value: "5432"
            - name: DB_PG_SCHEMA
              value: "public"
        image: swr.cn-north-4.myhuaweicloud.com/fjhb-prod/konga:0.14.9-arm64
        name: konga
      imagePullSecrets:
        - name: default-secret
EOF
cat <<EOF | kubectl apply -f  -
apiVersion: v1
kind: Service
metadata:
  name: konga
  namespace: kong
spec:
  ports:
  - name: http
    port: 1337
    protocol: TCP
    targetPort: 1337
  selector:
    app: konga
  type: NodePort
status:
  loadBalancer: {}
EOF
cat <<EOF | kubectl apply -f  -
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: ingress-konga
  namespace: kong
  labels:
    isExternal: 'true'
    zone: data
  annotations:
    ingress.beta.kubernetes.io/role: data
    ingress.kubernetes.io/secure-backends: 'false'
    kubernetes.io/elb.id: e8672dc9-4d65-49fa-99ad-ab9f316e9398
    kubernetes.io/elb.ip: 192.168.223.123
    kubernetes.io/elb.port: '80'
    protocol: HTTP
spec:
  rules:
    - host:  konga.59iedu.com
      http:
        paths:
          - path: /
            backend:
              serviceName: konga
              servicePort: 1337
            property:
              ingress.beta.kubernetes.io/url-match-mode: STARTS_WITH

status:
  loadBalancer:
    ingress:
      - ip: 192.168.223.123
EOF

访问测试