This commit is contained in:
Sharad Ahlawat
2021-04-20 12:34:43 -07:00
parent 2e8bdabea2
commit 10b9cbeead
22 changed files with 483 additions and 4 deletions

View File

@ -0,0 +1,25 @@
cd pyserver
docker build -t localhost:5000/pyserver:0.1 -f Dockerfile .
# docker build -t sahlawat/pyserver:0.1 -f Dockerfile .
docker run -it -p 8080:8080 --rm localhost:5000/pyserver:0.1
# curl localhost:8080
# docker run -d -p 8080:8080 diyit/pyserver:0.1
docker push localhost:5000/pyserver:0.1
kubectl create namespace demo
kubectl config set-context --current --namespace=demo
kubectl create deployment myapp --image=localhost:5000/pyserver:0.1
kubectl expose deployment myapp --port=8080 --type=LoadBalancer
# kubectl get service
# kubectl get all
# curl 172.18.255.200:8080
kubectl scale deployment myapp --replicas=3
# kubectl get service
kubectl delete service myapp
kubectl delete deployment myapp
kubectl delete namespace/demo

View File

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: myapp
name: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: localhost:5000/pyserver:v1
ports:
- containerPort: 8080

View File

@ -0,0 +1,9 @@
FROM python:3.8-slim-buster
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENTRYPOINT ["python"]
EXPOSE 8080
CMD ["app.py"]

14
k8s/apps/pyserver/app.py Normal file
View File

@ -0,0 +1,14 @@
from flask import Flask
import os
app = Flask(__name__)
@app.route('/')
def hello_world(count=0):
count += 1
return "Hello World! #" + str(count) + "\nfrom: " + os.getenv('HOSTNAME', "unknown") + "\n"
if __name__ == '__main__':
app.run(host='0.0.0.0', port='8080')

View File

@ -0,0 +1,3 @@
flask
flask_cors
dapr

View File

@ -0,0 +1,35 @@
kind: Pod
apiVersion: v1
metadata:
name: pyserver
labels:
app: pyserver
spec:
containers:
- name: pyserver
image: localhost:5000/pyserver:0.1
---
kind: Service
apiVersion: v1
metadata:
name: pyserver
spec:
selector:
app: pyserver
ports:
# Port used by the Docker image
- port: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pyserver-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: pyserver
servicePort: 8080
---