Merge pull request #161 from bmanojlovic/kubernetes

[mirotalk] add kubernetes deployment files
This commit is contained in:
Miroslav Pejic
2023-05-25 21:41:37 +02:00
committed by GitHub
7 changed files with 181 additions and 0 deletions
+3
View File
@@ -18,3 +18,6 @@ package-lock.json
.env
docker-push.sh
docker-compose.yml
output
env.txt
+25
View File
@@ -0,0 +1,25 @@
DOMAIN_NAME := $(shell sed -e '/HOST=/!d;s/HOST=//g' env.txt)
DOMAIN_NAME_DASHED := $(shell echo $(DOMAIN_NAME)|sed -e 's/[.]/-/g')
all: env.txt
@echo "default file env.txt created please run prepare and deploy if you adapted values in env.txt"
prepare:
@mkdir -p output
sed -e "s@__DOMAIN_NAME__@$(DOMAIN_NAME)@g;s@__DOMAIN_NAME_DASHED__@$(DOMAIN_NAME_DASHED)@g" *.yaml > output/mirotalk-k8s.yaml
deploy:
kubectl delete configmap p2p || echo "ignore error"
kubectl create configmap p2p --from-file=.env=env.txt
kubectl apply -f output/mirotalk-k8s.yaml
env.txt:
@test -f env.txt || cp -v ../.env.template env.txt
uninstall:
kubectl delete configmap p2p || :
kubectl delete -f output/mirotalk-k8s.yaml
delete:
kubectl delete configmap p2p || :
kubectl delete -f output/mirotalk-k8s.yaml
rm -rf env.txt output
+60
View File
@@ -0,0 +1,60 @@
# Kubernetes deployment
## TLDR; and do not care way
```
make
sed -i s/localhost/myshinydomain.tld/g env.txt
make prepare
# or make prepare-minikube
# for testing purposes
make deploy
```
# Understanding way
If you would like to deploy Mirotalk to kubernetes
this set of files can help you in that task
Bellow is explanation of files in this folder which will form one output file in `output` folder
## ../.env.template and your file env.txt that you should prepare
Configuration file that is for now used to configure deployment
you should copy `../.env.template` to current directory as `env.txt` and edit values inside to your liking
```
cp ../.env.template env.txt
```
Change values (if nothing else **HOST** variable must be changed so your ingress would recognize it and send requests to your deployed application),
if you do not have public domain you can use free service called [nip.io](https://nip.io/) with domain like `p2p.192-168-1-1.nip.io` (or [sslip.io](https://sslip.io/))
```
sed -i s/localhost/myshinydomain.tld/g env.txt
```
## p2p-deployment.yaml
Main deployment file where you change image file if you would like to use yours if not official one (`image`: tag)
## p2p-cert.yaml
This file represent definition of certificate (request) when using [Cert Manager](cert-manager.io) to generate letsencrypt or private certificates for your domain will be pulled out from `env.txt`
## p2p-ingress.yaml
This is generic ingress object in kubernetes that is responsible to route external traffic to mirotalk deployed application and if used in conjuction with p2p-cert.yaml (default) will provide TLS enabled access to your mirotalk instance
## p2p-service.yaml
Service required for ingress to be able to know how to access deployment
## Makefile
Helper file that allows running it to configure application how you would like
after creating and changing configuration file (`env.txt`) run these two tasks, prepare will create deployment file
and deployment will create configMap from prepared `env.txt` file.
Please run after reading all this:
```
make
# edit env.txt or use sed as in TLDR section :)
make prepare
make deploy
```
+15
View File
@@ -0,0 +1,15 @@
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: __DOMAIN_NAME_DASHED__-tls
spec:
duration: 2880h # 180d
renewBefore: 360h # 15d
commonName: __DOMAIN_NAME__
dnsNames:
- __DOMAIN_NAME__
issuerRef:
kind: ClusterIssuer
name: letsencrypt
secretName: __DOMAIN_NAME_DASHED__-tls
+35
View File
@@ -0,0 +1,35 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: p2p
name: p2p
spec:
replicas: 1
selector:
matchLabels:
app: p2p
strategy: {}
template:
metadata:
labels:
app: p2p
spec:
containers:
- image: mirotalk/p2p:latest
name: mirotalk
ports:
- containerPort: 3000
volumeMounts:
- name: p2p-env
mountPath: /src/.env
subPath: .env
resources: {}
volumes:
- name: p2p-env
configMap:
name: p2p
defaultMode: 0644
restartPolicy: Always
status: {}
+27
View File
@@ -0,0 +1,27 @@
---
apiVersion: v1
kind: List
metadata:
resourceVersion: ''
items:
- apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: p2p-ingress
spec:
rules:
- host: __DOMAIN_NAME__
http:
paths:
- backend:
service:
name: p2p
port:
number: 3000
path: /
pathType: Prefix
tls:
- hosts:
- __DOMAIN_NAME__
secretName: __DOMAIN_NAME_DASHED__-tls
status:
+16
View File
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Service
metadata:
labels:
app: p2p
name: p2p
spec:
ports:
- name: '3000'
port: 3000
targetPort: 3000
selector:
app: p2p
status:
loadBalancer: {}