flask-simple-ingress.yaml 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: flask-app
  5. namespace: nginx-app
  6. labels:
  7. app: flask-app
  8. spec:
  9. replicas: 2
  10. selector:
  11. matchLabels:
  12. app: flask-app
  13. template:
  14. metadata:
  15. labels:
  16. app: flask-app
  17. spec:
  18. containers:
  19. - name: flask
  20. image: registry.cn-hangzhou.aliyuncs.com/zhongpengqun/wanderer:amd64-linux-python-3.10-slim
  21. ports:
  22. - containerPort: 8000
  23. env:
  24. - name: FLASK_APP
  25. value: "app.py"
  26. command:
  27. - sh
  28. - -c
  29. - |
  30. pip install flask && \
  31. echo '
  32. from flask import Flask
  33. app = Flask(__name__)
  34. @app.route("/")
  35. def hello():
  36. return "<h1>Hello from Flask on port 8000!</h1>"
  37. @app.route("/hello")
  38. @app.route("/hello/")
  39. def hello_path():
  40. return "<h1>Hello from Flask /hello path! This redirects to root.</h1>"
  41. if __name__ == "__main__":
  42. app.run(host="0.0.0.0", port=8000)
  43. ' > /app.py && \
  44. python /app.py
  45. resources:
  46. requests:
  47. memory: "64Mi"
  48. cpu: "128m"
  49. limits:
  50. memory: "256Mi"
  51. cpu: "500m"
  52. ---
  53. apiVersion: v1
  54. kind: Service
  55. metadata:
  56. name: flask-service
  57. namespace: nginx-app
  58. labels:
  59. app: flask-app
  60. spec:
  61. selector:
  62. app: flask-app
  63. ports:
  64. - protocol: TCP
  65. port: 80
  66. targetPort: 8000
  67. type: ClusterIP
  68. ---
  69. apiVersion: networking.k8s.io/v1
  70. kind: Ingress
  71. metadata:
  72. name: flask-ingress
  73. namespace: nginx-app
  74. annotations:
  75. kubernetes.io/ingress.class: "traefik"
  76. spec:
  77. rules:
  78. - host: 215.9981.tech
  79. http:
  80. paths:
  81. - path: /hello
  82. pathType: Prefix
  83. backend:
  84. service:
  85. name: flask-service
  86. port:
  87. number: 80