wildcard.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. apiVersion: v1
  2. kind: Template
  3. metadata:
  4. name: "amp-apicast-wildcard-router"
  5. objects:
  6. - apiVersion: v1
  7. kind: DeploymentConfig
  8. metadata:
  9. name: apicast-router
  10. spec:
  11. replicas: 1
  12. selector:
  13. deploymentconfig: apicast-router
  14. strategy:
  15. type: Rolling
  16. template:
  17. metadata:
  18. labels:
  19. deploymentconfig: apicast-router
  20. spec:
  21. volumes:
  22. - name: apicast-router-config
  23. configMap:
  24. name: apicast-router-config
  25. items:
  26. - key: router.conf
  27. path: router.conf
  28. containers:
  29. - env:
  30. - name: APICAST_CONFIGURATION_LOADER
  31. value: "lazy"
  32. - name: APICAST_CONFIGURATION_CACHE
  33. value: "0"
  34. image: 3scale-amp20/apicast-gateway:1.0-3
  35. imagePullPolicy: IfNotPresent
  36. name: apicast-router
  37. command: ['bin/apicast']
  38. livenessProbe:
  39. tcpSocket:
  40. port: router
  41. initialDelaySeconds: 5
  42. timeoutSeconds: 5
  43. periodSeconds: 10
  44. readinessProbe:
  45. httpGet:
  46. path: /status/ready
  47. port: management
  48. initialDelaySeconds: 5
  49. timeoutSeconds: 5
  50. periodSeconds: 30
  51. volumeMounts:
  52. - name: apicast-router-config
  53. mountPath: /opt/app-root/src/sites.d/
  54. readOnly: true
  55. ports:
  56. - containerPort: 8082
  57. name: router
  58. protocol: TCP
  59. - containerPort: 8090
  60. name: management
  61. protocol: TCP
  62. triggers:
  63. - type: ConfigChange
  64. - apiVersion: v1
  65. kind: Service
  66. metadata:
  67. name: apicast-router
  68. spec:
  69. ports:
  70. - name: router
  71. port: 80
  72. protocol: TCP
  73. targetPort: router
  74. selector:
  75. deploymentconfig: apicast-router
  76. - apiVersion: v1
  77. kind: ConfigMap
  78. metadata:
  79. name: apicast-router-config
  80. data:
  81. router.conf: |-
  82. upstream wildcard {
  83. server 0.0.0.1:1;
  84. balancer_by_lua_block {
  85. local round_robin = require 'resty.balancer.round_robin'
  86. local balancer = round_robin.new()
  87. local peers = balancer:peers(ngx.ctx.apicast)
  88. local peer, err = balancer:set_peer(peers)
  89. if not peer then
  90. ngx.status = ngx.HTTP_SERVICE_UNAVAILABLE
  91. ngx.log(ngx.ERR, "failed to set current backend peer: ", err)
  92. ngx.exit(ngx.status)
  93. end
  94. }
  95. keepalive 1024;
  96. }
  97. server {
  98. listen 8082;
  99. server_name ~-(?<apicast>apicast-(staging|production))\.;
  100. access_log /dev/stdout combined;
  101. location / {
  102. access_by_lua_block {
  103. local resolver = require('resty.resolver'):instance()
  104. local servers = resolver:get_servers(ngx.var.apicast, { port = 8080 })
  105. if #servers == 0 then
  106. ngx.status = ngx.HTTP_BAD_GATEWAY
  107. ngx.exit(ngx.HTTP_OK)
  108. end
  109. ngx.ctx.apicast = servers
  110. }
  111. proxy_http_version 1.1;
  112. proxy_pass $scheme://wildcard;
  113. proxy_set_header Host $host;
  114. proxy_set_header Connection "";
  115. }
  116. }
  117. - apiVersion: v1
  118. kind: Route
  119. metadata:
  120. name: apicast-wildcard-router
  121. labels:
  122. app: apicast-wildcard-router
  123. spec:
  124. host: apicast-${TENANT_NAME}.${WILDCARD_DOMAIN}
  125. to:
  126. kind: Service
  127. name: apicast-router
  128. port:
  129. targetPort: router
  130. wildcardPolicy: Subdomain
  131. tls:
  132. termination: edge
  133. insecureEdgeTerminationPolicy: Allow
  134. parameters:
  135. - name: AMP_RELEASE
  136. description: "AMP release tag."
  137. value: 2.0.0-CR2-redhat-1
  138. required: true
  139. - name: WILDCARD_DOMAIN
  140. description: Root domain for the wildcard routes. Eg. example.com will generate 3scale-admin.example.com.
  141. required: true
  142. - name: TENANT_NAME
  143. description: "Domain name under the root that Admin UI will be available with -admin suffix."
  144. required: true
  145. value: "3scale"