项目作者: niteenkole

项目描述 :
pgadmin4 on AKS (azure kubernetes cluster) behind AGIC (application gateway ingress control) with azure file storage as PV
高级语言:
项目地址: git://github.com/niteenkole/pgadmin4.git
创建时间: 2020-05-26T14:20:17Z
项目社区:https://github.com/niteenkole/pgadmin4

开源协议:

下载


Table of Contents

About The Project

How to setup pgadmin4 end to end ssl in azure kubernetes cluster behind azure application ingress controller AGIC.

pgadmin4 on AKS (azure kubernetes cluster) behind AGIC (application gateway ingress control) with azure file storage as PV

Built With

Getting Started

1.Setup PV and PVC
2.Setup secrets
3.Apply root certificate to AGIC
4.Setup deployment
5.Setup service
6.Setup ingress for AGIC
7.Verify

Prerequisites

Assuming you have below up and running
AKS
AGIC

Installation

  1. Setup pv and PVC

a. create secret

  1. STORAGE_KEY=$(az storage account keys list --resource-group RGname --account-name storageaccountname --query "[0].value" -o tsv)

b. Create NS

  1. kubectl create ns pgadmin

c. Create azure storage secret

  1. kubectl create secret generic pgadmin-azure-secret --from-literal=azurestorageaccountname=storageaccountname --from-literal=azurestorageaccountkey=$STORAGE_KEY -n pgadmin

d. Create PersistentVolume

pv-azurefile-mountoptions-pgadmin-var.yaml

  1. Note you need ReadWriteMany
  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: pv-azurefile-pgadmin-var
  5. spec:
  6. capacity:
  7. storage: 20Gi
  8. accessModes:
  9. - ReadWriteMany
  10. azureFile:
  11. secretName: pgadmin-azure-secret
  12. shareName: pgadmin-var-data
  13. readOnly: false
  14. mountOptions:
  15. - dir_mode=0777
  16. - file_mode=0777
  17. - uid=5050
  18. - mfsymlinks
  19. - nobrl

====================================

Note share should exist inside your storage,if not create it

  1. kubectl create -f pv-azurefile-mountoptions-pgadmin-var.yaml
  1. kubectl get pv
  2. NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
  3. pv-azurefile-pgadmin-var 20Gi RWX Retain Bound pgadmin/pvc-azurefile-pgadmin-var 17h

e. Create PersistentVolumeClaim

pvc-azurefile-static-pgadmin-var.yaml

  1. kind: PersistentVolumeClaim
  2. apiVersion: v1
  3. metadata:
  4. name: pvc-azurefile-pgadmin-var
  5. spec:
  6. accessModes:
  7. - ReadWriteMany
  8. resources:
  9. requests:
  10. storage: 20Gi
  11. storageClassName: ""
  12. volumeName: pv-azurefile-pgadmin-var
  1. kubectl create -f pvc-azurefile-static-pgadmin-var.yaml -n pgadmin
  1. kubectl get pvc -n pgadmin
  2. NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
  3. pvc-azurefile-pgadmin-var Bound pv-azurefile-pgadmin-var 20Gi RWX 17h
  1. setup secrets

Note for safe side we use private registry and we dont want pgadmin to pull latest image if container is restared.
We pull pgadmin4 and push in private registry.

a.Image pull secret

  1. kubectl --namespace pgadmin create secret docker-registry pgadmin-pull-secret --docker-server=xx.xx.xx --docker-username=abcd --docker-password=Hxxxxxxbinxxx8O --docker-email=niteen_kole@xxxxxx.ca

b. pgadmin ssl certificate secret.

  1. kubectl create secret generic pgadmin-ssl-key --from-file=/certs/server.key --from-file=/certs/server.cert -n pgadmin

Note your server.cert should include all server,root and intermidiate

example.

  1. cat server.cert
  2. -----BEGIN CERTIFICATE-----
  3. MIIHTTCCBjWgAwIBAgIRAMHZwo2wytiNAAAAAFDzaT0wDQYJKoZIhvcNAQELBQAw
  4. gboxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1FbnRydXN0LCBJbmMuMSgwJgYDVQQL
  5. ....
  6. ....
  7. -----END CERTIFICATE-----
  8. -----BEGIN CERTIFICATE-----
  9. MIIEPjCCAyagAwIBAgIESlOMKDANBgkqhkiG9w0BAQsFADCBvjELMAkGA1UEBhMC
  10. VVMxFjAUBgNVBAoTDUVudHJ1c3QsIEluYy4xKDAmBgNVBAsTH1NlZSB3d3cuZW50
  11. ....
  12. ....
  13. -----END CERTIFICATE-----
  14. -----BEGIN CERTIFICATE-----
  15. MIIFDjCCA/agAwIBAgIMDulMwwAAAABR03eFMA0GCSqGSIb3DQEBCwUAMIG+MQsw
  16. CQYDVQQGEwJVUzEWMBQGA1UEChMNRW50cnVzdCwgSW5jLjEoMCYGA1UECxMfU2Vl
  17. ....
  18. ....
  19. -----END CERTIFICATE-----

c. TLS secret for ingress.

  1. kubectl create secret tls pgadmin-ingress-portal-tls -n pgadmin --key="server.key" --cert="server.cert"
  1. Apply root certificate to AGIC

a. Point to subscription where your AGW is running

b. Apply root certificate

  1. az network application-gateway root-cert create --cert-file root.cer --gateway-name APPgwname --name root-cert1 --resource-group AGWRG-Name
  1. Setup deployment

pgadmin-deployment-tls-file.yaml

  1. kind: Deployment
  2. apiVersion: apps/v1
  3. metadata:
  4. name: pgadmin-prod
  5. namespace: pgadmin
  6. labels:
  7. k8s-app: pgadmin-prod
  8. application-name: pgadmin-prod
  9. version-no: "01"
  10. owner: niteen_kole
  11. env: production
  12. release-no: "01"
  13. tier: "01"
  14. customer-facing: "yes"
  15. app-role: web
  16. project-id: design
  17. annotations:
  18. deployment.kubernetes.io/revision: '1'
  19. spec:
  20. replicas: 1
  21. selector:
  22. matchLabels:
  23. k8s-app: pgadmin-prod
  24. application-name: pgadmin-prod
  25. version-no: "01"
  26. owner: niteen_kole
  27. env: production
  28. release-no: "01"
  29. tier: "01"
  30. customer-facing: "yes"
  31. app-role: web
  32. project-id: design
  33. template:
  34. metadata:
  35. name: pgadmin-prod
  36. creationTimestamp:
  37. labels:
  38. k8s-app: pgadmin-prod
  39. application-name: pgadmin-prod
  40. version-no: "01"
  41. owner: niteen_kole
  42. env: production
  43. release-no: "01"
  44. tier: "01"
  45. customer-facing: "yes"
  46. app-role: web
  47. project-id: design
  48. spec:
  49. containers:
  50. - name: pgadmin-prod
  51. image: your-registry/pgadmin4:latest
  52. volumeMounts:
  53. - name: pgadmin-var
  54. mountPath: /var/lib/pgadmin
  55. - name: pgadmin-cert
  56. mountPath: /certs
  57. env:
  58. - name: PGADMIN_DEFAULT_EMAIL
  59. value: "niteen_kole@xxxxx.ca"
  60. - name: PGADMIN_DEFAULT_PASSWORD
  61. value: "XXXXXXX"
  62. - name: PGADMIN_ENABLE_TLS
  63. value: "True"
  64. - name: PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION
  65. value: "False"
  66. resources: {}
  67. imagePullPolicy: Always
  68. imagePullSecrets:
  69. - name: pgadmin-pull-secret
  70. schedulerName: default-scheduler
  71. volumes:
  72. - name: pgadmin-var
  73. persistentVolumeClaim:
  74. claimName: pvc-azurefile-pgadmin-var
  75. - name: pgadmin-cert
  76. secret:
  77. secretName: pgadmin-ssl-key
  1. kubectl create -f pgadmin-deployment-tls-file.yaml -n pgadmin

5.Setup service

pgadmin-prod-svc.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: pgadmin-svc
  5. namespace: pgadmin
  6. spec:
  7. ports:
  8. - port: 443
  9. targetPort: 443
  10. protocol: TCP
  11. type: ClusterIP
  12. selector:
  13. k8s-app: pgadmin-prod
  1. kubectl create -f pgadmin-prod-svc.yaml -n pgadmin

6.Setup ingress for AGIC

pgadmin-ingress.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: pgadmin-ingress
  5. namespace: pgadmin
  6. annotations:
  7. kubernetes.io/ingress.class: azure/application-gateway
  8. appgw.ingress.kubernetes.io/backend-protocol: "https"
  9. appgw.ingress.kubernetes.io/backend-hostname: "pg.xxxxx.com"
  10. appgw.ingress.kubernetes.io/appgw-trusted-root-certificate: "root-cert1"
  11. spec:
  12. tls:
  13. - hosts:
  14. - pg.xxxxx.com
  15. secretName: pgadmin-ingress-portal-tls
  16. rules:
  17. - host: pg.xxxxx.com
  18. http:
  19. paths:
  20. - path:
  21. backend:
  22. serviceName: pgadmin-svc
  23. servicePort: 443
  1. kubectl create -f pgadmin-ingress.yaml -n pgadmin

7.Verify

  1. kubectl get all -n pgadmin
  2. NAME READY STATUS RESTARTS AGE
  3. pod/pgadmin-prod-7fd8944c75-z5vjk 1/1 Running 0 3h2m
  4. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  5. service/pgadmin-lb-pvt LoadBalancer xxx.xx.xxx.xx xxx.xx.xxx.xx 443:32450/TCP 3h1m
  6. service/pgadmin-svc ClusterIP xxx.xx.xxx.xx <none> 443/TCP 19h
  7. NAME READY UP-TO-DATE AVAILABLE AGE
  8. deployment.apps/pgadmin-prod 1/1 1 1 3h2m
  1. kubectl get ingress -n pgadmin
  2. NAME HOSTS ADDRESS PORTS AGE
  3. pgadmin-ingress pg.xxxxx.com xxx.xx.xxx.xx 80, 443 165m

Contact

Project Link: https://github.com/niteenkole/pgadmin4

Acknowledgements