|
| 1 | +apiVersion: v1 |
| 2 | +kind: Namespace |
| 3 | +metadata: |
| 4 | + name: gke-weather-app |
| 5 | + |
| 6 | +--- |
| 7 | +apiVersion: v1 |
| 8 | +kind: PersistentVolumeClaim |
| 9 | +metadata: |
| 10 | + name: consul-pvc |
| 11 | + namespace: gke-weather-app |
| 12 | +spec: |
| 13 | + accessModes: |
| 14 | + - ReadWriteOnce |
| 15 | + resources: |
| 16 | + requests: |
| 17 | + storage: 32Mi |
| 18 | +--- |
| 19 | +apiVersion: v1 |
| 20 | +kind: PersistentVolumeClaim |
| 21 | +metadata: |
| 22 | + name: redis-pvc |
| 23 | + namespace: gke-weather-app |
| 24 | +spec: |
| 25 | + accessModes: |
| 26 | + - ReadWriteOnce |
| 27 | + resources: |
| 28 | + requests: |
| 29 | + storage: 32Mi |
| 30 | +--- |
| 31 | +# k8s manifests consul deployment.yaml |
| 32 | +apiVersion: apps/v1 |
| 33 | +kind: Deployment |
| 34 | +metadata: |
| 35 | + name: consul-ssm |
| 36 | + namespace: gke-weather-app |
| 37 | +spec: |
| 38 | + replicas: 1 |
| 39 | + selector: |
| 40 | + matchLabels: |
| 41 | + app: consul-ssm |
| 42 | + template: |
| 43 | + metadata: |
| 44 | + labels: |
| 45 | + app: consul-ssm |
| 46 | + spec: |
| 47 | + containers: |
| 48 | + - name: consul |
| 49 | + image: ianunay/weather-app-ssm:v1 |
| 50 | + ports: |
| 51 | + - containerPort: 8500 |
| 52 | + - containerPort: 8600 |
| 53 | + volumeMounts: |
| 54 | + - mountPath: /consul/data |
| 55 | + name: consul-data |
| 56 | + volumes: |
| 57 | + - name: consul-data |
| 58 | + persistentVolumeClaim: |
| 59 | + claimName: consul-pvc |
| 60 | +--- |
| 61 | +# k8s manifests consul service.yaml |
| 62 | +apiVersion: v1 |
| 63 | +kind: Service |
| 64 | +metadata: |
| 65 | + name: consul-ssm |
| 66 | + namespace: gke-weather-app |
| 67 | +spec: |
| 68 | + type: ClusterIP |
| 69 | + ports: |
| 70 | + - name: http |
| 71 | + port: 8500 |
| 72 | + targetPort: 8500 |
| 73 | + - name: dns |
| 74 | + port: 8600 |
| 75 | + targetPort: 8600 |
| 76 | + selector: |
| 77 | + app: consul-ssm |
| 78 | +--- |
| 79 | +# k8s manifests redis deployment.yaml |
| 80 | +apiVersion: apps/v1 |
| 81 | +kind: Deployment |
| 82 | +metadata: |
| 83 | + name: redis-cache-weather-prediction |
| 84 | + namespace: gke-weather-app |
| 85 | +spec: |
| 86 | + replicas: 1 |
| 87 | + selector: |
| 88 | + matchLabels: |
| 89 | + app: redis-cache-weather-prediction |
| 90 | + template: |
| 91 | + metadata: |
| 92 | + labels: |
| 93 | + app: redis-cache-weather-prediction |
| 94 | + spec: |
| 95 | + containers: |
| 96 | + - name: redis |
| 97 | + image: redis:latest |
| 98 | + ports: |
| 99 | + - containerPort: 6379 |
| 100 | + volumeMounts: |
| 101 | + - mountPath: /data |
| 102 | + name: redis-data |
| 103 | + volumes: |
| 104 | + - name: redis-data |
| 105 | + persistentVolumeClaim: |
| 106 | + claimName: redis-pvc |
| 107 | +--- |
| 108 | +# k8s manifests redis service.yaml |
| 109 | +apiVersion: v1 |
| 110 | +kind: Service |
| 111 | +metadata: |
| 112 | + name: redis-cache-weather-prediction |
| 113 | + namespace: gke-weather-app |
| 114 | +spec: |
| 115 | + type: ClusterIP |
| 116 | + ports: |
| 117 | + - port: 6379 |
| 118 | + targetPort: 6379 |
| 119 | + selector: |
| 120 | + app: redis-cache-weather-prediction |
| 121 | +--- |
| 122 | +apiVersion: apps/v1 |
| 123 | +kind: Deployment |
| 124 | +metadata: |
| 125 | + name: api |
| 126 | + namespace: gke-weather-app |
| 127 | +spec: |
| 128 | + replicas: 1 |
| 129 | + selector: |
| 130 | + matchLabels: |
| 131 | + app: api |
| 132 | + template: |
| 133 | + metadata: |
| 134 | + labels: |
| 135 | + app: api |
| 136 | + spec: |
| 137 | + containers: |
| 138 | + - name: api |
| 139 | + image: ianunay/weather-app-api:v6 |
| 140 | + ports: |
| 141 | + - containerPort: 8080 |
| 142 | + env: |
| 143 | + - name: CONSUL_HTTP_ADDR |
| 144 | + value: "consul-ssm:8500" |
| 145 | + |
| 146 | +--- |
| 147 | + |
| 148 | +apiVersion: v1 |
| 149 | +kind: Service |
| 150 | +metadata: |
| 151 | + name: api |
| 152 | + namespace: gke-weather-app |
| 153 | +spec: |
| 154 | + type: ClusterIP |
| 155 | + ports: |
| 156 | + - port: 8080 |
| 157 | + targetPort: 8080 |
| 158 | + selector: |
| 159 | + app: api |
| 160 | + |
| 161 | +--- |
| 162 | +# k8s manifests ui deployment.yaml |
| 163 | +apiVersion: apps/v1 |
| 164 | +kind: Deployment |
| 165 | +metadata: |
| 166 | + name: ui |
| 167 | + namespace: gke-weather-app |
| 168 | +spec: |
| 169 | + replicas: 1 |
| 170 | + selector: |
| 171 | + matchLabels: |
| 172 | + app: ui |
| 173 | + template: |
| 174 | + metadata: |
| 175 | + labels: |
| 176 | + app: ui |
| 177 | + spec: |
| 178 | + containers: |
| 179 | + - name: ui |
| 180 | + image: ianunay/weather-app-ui:v2 |
| 181 | + ports: |
| 182 | + - containerPort: 5001 |
| 183 | +--- |
| 184 | +# k8s manifests ui service.yaml |
| 185 | +apiVersion: v1 |
| 186 | +kind: Service |
| 187 | +metadata: |
| 188 | + name: ui |
| 189 | + namespace: gke-weather-app |
| 190 | +spec: |
| 191 | + type: NodePort |
| 192 | + ports: |
| 193 | + - port: 5001 |
| 194 | + targetPort: 5001 |
| 195 | + nodePort: 31001 |
| 196 | + selector: |
| 197 | + app: ui |
| 198 | +--- |
| 199 | +apiVersion: v1 |
| 200 | +kind: ConfigMap |
| 201 | +metadata: |
| 202 | + name: nginx-config |
| 203 | + namespace: gke-weather-app |
| 204 | +data: |
| 205 | + nginx.conf: | |
| 206 | + events {} |
| 207 | + http { |
| 208 | + log_format custom '$remote_addr - $remote_user [$time_local] "$request" ' |
| 209 | + '$status $body_bytes_sent "$http_referer" ' |
| 210 | + '"$http_user_agent" "$http_x_forwarded_for" ' |
| 211 | + 'upstream: $upstream_addr request_time: $request_time upstream_response_time: $upstream_response_time'; |
| 212 | + |
| 213 | + access_log /var/log/nginx/access.log custom; |
| 214 | + error_log /var/log/nginx/error.log; |
| 215 | + |
| 216 | + server { |
| 217 | + listen 80; |
| 218 | + |
| 219 | + location /api/ { |
| 220 | + rewrite ^/api/(.*)$ /$1 break; |
| 221 | + proxy_http_version 1.1; |
| 222 | + proxy_cache_bypass $http_upgrade; |
| 223 | + |
| 224 | + proxy_set_header Upgrade $http_upgrade; |
| 225 | + proxy_set_header Connection 'upgrade'; |
| 226 | + proxy_set_header Host $host; |
| 227 | + proxy_set_header X-Real-IP $remote_addr; |
| 228 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 229 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 230 | + |
| 231 | + add_header Accept "application/json"; |
| 232 | + |
| 233 | + proxy_pass http://api:8080; |
| 234 | + } |
| 235 | + |
| 236 | + location / { |
| 237 | + proxy_http_version 1.1; |
| 238 | + proxy_cache_bypass $http_upgrade; |
| 239 | + |
| 240 | + proxy_set_header Upgrade $http_upgrade; |
| 241 | + proxy_set_header Connection 'upgrade'; |
| 242 | + proxy_set_header Host $host; |
| 243 | + proxy_set_header X-Real-IP $remote_addr; |
| 244 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 245 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 246 | + |
| 247 | + proxy_pass http://ui:5001; |
| 248 | + } |
| 249 | + |
| 250 | + location ~* \.(eot|ttf|woff|woff2)$ { |
| 251 | + add_header Access-Control-Allow-Origin *; |
| 252 | + } |
| 253 | + } |
| 254 | + } |
| 255 | +--- |
| 256 | +apiVersion: apps/v1 |
| 257 | +kind: Deployment |
| 258 | +metadata: |
| 259 | + name: nginx |
| 260 | + namespace: gke-weather-app |
| 261 | +spec: |
| 262 | + replicas: 1 |
| 263 | + selector: |
| 264 | + matchLabels: |
| 265 | + app: nginx |
| 266 | + template: |
| 267 | + metadata: |
| 268 | + labels: |
| 269 | + app: nginx |
| 270 | + spec: |
| 271 | + containers: |
| 272 | + - name: nginx |
| 273 | + image: ianunay/weather-app-nginx:v4 |
| 274 | + ports: |
| 275 | + - containerPort: 80 |
| 276 | + volumeMounts: |
| 277 | + - name: nginx-config |
| 278 | + mountPath: /etc/nginx/nginx.conf |
| 279 | + subPath: nginx.conf |
| 280 | + volumes: |
| 281 | + - name: nginx-config |
| 282 | + configMap: |
| 283 | + name: nginx-config |
| 284 | +--- |
| 285 | +apiVersion: v1 |
| 286 | +kind: Service |
| 287 | +metadata: |
| 288 | + name: nginx |
| 289 | + namespace: gke-weather-app |
| 290 | +spec: |
| 291 | + type: LoadBalancer |
| 292 | + ports: |
| 293 | + - port: 80 |
| 294 | + targetPort: 80 |
| 295 | + nodePort: 30080 |
| 296 | + selector: |
| 297 | + app: nginx |
| 298 | +--- |
| 299 | +# kube proxy will not be needed for AWS EKS. |
| 300 | +# In a cloud environment like AWS, a LoadBalancer service is needed to expose the applications. |
| 301 | +# The NodePort service (as used in local development with port-forwarder) should be changed to a LoadBalancer service for AWS EKS. |
| 302 | +# This will allow the service to be accessible via an external load balancer. |
| 303 | +# In AWS, the external load balancer for Kubernetes services is typically an Application Load Balancer (ALB) when you need advanced routing capabilities, such as path-based or host-based routing or http/https routing. |
| 304 | +# If a simpler, high-performance load balancer is needed, a Network Load Balancer (NLB) is ideal use. |
0 commit comments