Start two simple projects

main
John Kenyon 2025-06-20 18:06:47 -07:00
commit 8c89d039c4
11 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30125 # Optional: fixed NodePort

6
simple-proj/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM python:3.11-slim
WORKDIR /app
COPY app.py .
RUN pip install flask redis
CMD ["python", "app.py"]

21
simple-proj/app.py Normal file
View File

@ -0,0 +1,21 @@
# app.py
from flask import Flask, request, jsonify
import redis
r = redis.Redis(host='redis', port=6379)
app = Flask(__name__)
@app.route("/items", methods=["GET", "POST"])
def items():
if request.method == "POST":
item = request.json.get("item")
if item:
r.rpush("shopping_list", item)
return '', 204
else:
items = r.lrange("shopping_list", 0, -1)
return jsonify([i.decode() for i in items])
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)

View File

View File

View File

@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shoppinglist-frontend
spec:
replicas: 1
selector:
matchLabels:
app: shoppinglist-frontend
template:
metadata:
labels:
app: shoppinglist-frontend
spec:
containers:
- name: frontend
image: shoppinglist-frontend:latest
ports:
- containerPort: 5000
env:
- name: REDIS_HOST
value: redis
- name: REDIS_PORT
value: "6379"

View File

@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: shoppinglist-frontend
spec:
selector:
app: shoppinglist-frontend
ports:
- port: 80
targetPort: 5000
type: NodePort

View File

@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:7-alpine
ports:
- containerPort: 6379

View File

@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
selector:
app: redis
ports:
- port: 6379
targetPort: 6379
type: ClusterIP

View File

View File