一、创建命名空间:
> kubectl create ns kong
二、创建yaml文件(deploy.yaml),内容如下
##1、创建 postgres 数据库:
apiVersion: apps/v1
kind: Deployment
metadata:
name: kong-pgs
namespace: kong
spec:
replicas: 1
selector:
matchLabels:
application: kong-pgs
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
application: kong-pgs
spec:
containers:
- name: kong-pgs
env:
- name: POSTGRES_USER
value: kong
- name: POSTGRES_DB
value: kong
- name: POSTGRES_PASSWORD
value: kong
- name: PGDATA
value: "/var/lib/postgresql/data"
image: postgres:9.6
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5432
protocol: TCP
name: postgresql-port
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: pgs-storage
restartPolicy: Always
terminationGracePeriodSeconds: 30
volumes:
- name: pgs-storage
hostPath:
path: /kong/pgs
---
apiVersion: v1
kind: Service
metadata:
name: kong-pgs
namespace: kong
spec:
ports:
- name: port-5432
port: 5432
protocol: TCP
targetPort: 5432
nodePort: 35432
selector:
application: kong-pgs
type: NodePort
---
##2、初始化 kong 数据及部署 kong:
apiVersion: apps/v1
kind: Deployment
metadata:
name: kong
namespace: kong
spec:
replicas: 1
selector:
matchLabels:
application: kong
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
application: kong
spec:
# 初始化pgs数据库
initContainers:
- name: init-pgs
image: kong:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","kong migrations bootstrap"]
env:
- name: KONG_PG_HOST
value: kong-pgs.kong.svc.cluster.local
- name: KONG_PG_PORT
value: "5432"
- name: KONG_PG_PASSWORD
value: kong
- name: KONG_DATABASE
value: postgres
containers:
- name: kong
env:
- name: KONG_PG_HOST
value: kong-pgs.kong.svc.cluster.local
- name: KONG_PG_PORT
value: "5432"
- name: KONG_PG_PASSWORD
value: kong
- name: KONG_DATABASE
value: postgres
- name: KONG_PROXY_ERROR_LOG
value: /dev/stderr
- name: KONG_PROXY_ACCESS_LOG
value: /dev/stdout
- name: KONG_ADMIN_ACCESS_LOG
value: /dev/stdout
- name: KONG_ADMIN_ERROR_LOG
value: /dev/stderr
- name: KONG_ADMIN_LISTEN
value: 0.0.0.0:8001, 0.0.0.0:8444
- name: KONG_LOG_LEVEL
value: error
- name: KONG_NGINX_WORKER_PROCESSES
value: "3"
image: kong:latest
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /status
port: 8001
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 20
successThreshold: 1
successThreshold: 1
timeoutSeconds: 6
ports:
- name: kong-proxy
containerPort: 8000
protocol: TCP
- name: kong-admin
containerPort: 8001
protocol: TCP
- name: kong-proxy-ssl
containerPort: 8443
protocol: TCP
- name: kong-admin-ssl
containerPort: 8444
protocol: TCP
readinessProbe:
failureThreshold: 1
httpGet:
path: /status
port: 8001
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 20
successThreshold: 1
timeoutSeconds: 6
restartPolicy: Always
terminationGracePeriodSeconds: 30
---
kind: Service
apiVersion: v1
metadata:
name: kong-port
namespace: kong
spec:
type: NodePort
ports:
- name: http
protocol: TCP
port: 8000
targetPort: 8000
nodePort: 30800
- name: https
protocol: TCP
port: 8443
targetPort: 8443
nodePort: 32443
- name: admin
protocol: TCP
port: 8001
targetPort: 8001
nodePort: 30801
selector:
application: kong
---
##3、部署 konga:
apiVersion: apps/v1
kind: Deployment
metadata:
name: konga
namespace: kong
spec:
replicas: 1
selector:
matchLabels:
application: konga
template:
metadata:
labels:
application: konga
spec:
containers:
- name: konga
env:
- name: KONGA_LOG_LEVEL
value: info
- name: NODE_ENV
value: development #生产:production
- name: DB_ADAPTER # 指定数据库类型
value: postgres
- name: DB_HOST
value: kong-pgs.kong.svc.cluster.local
- name: DB_PORT
value: "5432"
- name: DB_USER
value: kong
- name: DB_PASSWORD
value: kong
- name: DB_DATABASE
value: postgres
image: pantsel/konga:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 1337
protocol: TCP
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: konga-svc
namespace: kong
labels:
app: konga-svc
spec:
ports:
- name: port-1337
port: 1337
protocol: TCP
targetPort: 1337
nodePort: 31337
selector:
application: konga
type: NodePort
三、执行yaml部署
> kubectl apply -f deploy.yaml
四、创建管理员账号
五、配置连接connections
Name
kong
Kong Admin URL
http://[node-ip]:30801