Add kubernetes files and shell scripts for test deployment

This commit is contained in:
David Eder 2021-05-02 22:31:00 +02:00
parent 5c6be895e4
commit dae1700704
10 changed files with 173 additions and 31 deletions

View File

@ -5,3 +5,57 @@ Django Backend
* Start both middleware AND frontend dev server simultaneously * Start both middleware AND frontend dev server simultaneously
* See README of subfolder for further information * See README of subfolder for further information
## Deploy Kubernetes Admin Dashboard
Deploy dashboard:
```
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
```
Create dashboard-admin.yaml file:
```
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
```
Apply it to kubernetes:
```
kubectl apply -f dashboard-admin.yaml
```
Get login token:
```
kubectl get secret -n kubernetes-dashboard $(kubectl get serviceaccount admin-user -n kubernetes-dashboard -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data.token}" | base64 --decode
```
Start proxy:
```
kubectl proxy
```
Access URL: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/ingress?namespace=default
## Fix Darwin issue with Ingress
```
minikube stop && minikube delete && minikube start --vm=true --driver=hyperkit
```

View File

@ -1,31 +0,0 @@
from flask import Flask
from flask_pymongo import PyMongo
# make sure mongoDB (container) is running and accessible
# see https://flask-pymongo.readthedocs.io/en/latest/
app = Flask(__name__)
app.config["MONGO_URI"] = "mongodb://localhost:27017/myDatabase"
mongo = PyMongo(app)
mongo.db.test.save({'_id': 0, 'foo': {'test': 'this'}})
mongo.db.test.save({'_id': 1, 'suu': 'sar'})
@app.route("/")
def home_page():
test_results = mongo.db.test.find()
results = []
try:
while True:
result = test_results.next()
results.append(result)
except StopIteration:
pass
return str(results)
if __name__ == '__main__':
app.run()

View File

@ -0,0 +1,8 @@
FROM python:3.8-slim
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENV PORT 5000
EXPOSE 5000
ENTRYPOINT [ "python" ]
CMD [ "entity_ident.py" ]

View File

@ -0,0 +1,38 @@
import jsonify as jsonify
from flask import Flask
from flask_pymongo import PyMongo
# make sure mongoDB (container) is running and accessible
# see https://flask-pymongo.readthedocs.io/en/latest/
app = Flask(__name__)
#app.config["MONGO_URI"] = "mongodb://localhost:27017/myDatabase"
#mongo = PyMongo(app)
#mongo.db.test.insert_one({'_id': 0, 'foo': {'test': 'this'}})
#mongo.db.test.insert_one({'_id': 1, 'suu': 'sar'})
#@app.route("/")
#def home_page():
# test_results = mongo.db.test.find()
# results = []
# try:
# while True:
# result = test_results.next()
# results.append(result)
# except StopIteration:
# pass
#return str(results)
@app.route("/")
def index():
return str("Welcome to Tasks app! I am running inside pod!")
#if __name__ == '__main__':
# app.run()
if __name__ == '__main__':
app.run(host='0.0.0.0')

View File

@ -1,3 +1,4 @@
pika pika
flask flask
Flask-PyMongo Flask-PyMongo
jsonify

17
deploy-local.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
echo "Pointing shell to minikubes docker-daemon..."
eval $(minikube -p minikube docker-env)
echo "Building images..."
docker build -t entity-ident components/entitiy_ident/entity_ident_service
echo "Creating deployments and services..."
kubectl create -f kubernetes/entity-ident-deployment.yaml
kubectl create -f kubernetes/entity-ident-service.yaml
echo "Enabling Ingress addon..."
minikube addons enable ingress
echo "Creating the Ingress object..."
kubectl apply -f kubernetes/minikube-ingress.yaml

View File

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: entity-ident
labels:
app: entity-ident
spec:
replicas: 1
selector:
matchLabels:
app: entity-ident
template:
metadata:
labels:
app: entity-ident
spec:
containers:
- name: entity-ident
image: entity-ident
ports:
- containerPort: 5000
imagePullPolicy: Never

View File

@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: entity-ident
labels:
service: entity-ident
spec:
selector:
app: entity-ident
ports:
- port: 5000
targetPort: 5000

View File

@ -0,0 +1,15 @@
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
serviceName: entity-ident
servicePort: 5000

6
remove-local.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
echo "Removing deployments and services..."
kubectl delete -f kubernetes/entity-ident-deployment.yaml
kubectl delete -f kubernetes/entity-ident-service.yaml
kubectl delete -f kubernetes/minikube-ingress.yaml