diff --git a/homework/ymh-webapp/backend-Dockerfile b/homework/ymh-webapp/backend-Dockerfile new file mode 100644 index 0000000..21b5cb3 --- /dev/null +++ b/homework/ymh-webapp/backend-Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.10 + +WORKDIR /app + +COPY . /app + +RUN pip3 install --no-cache-dir --upgrade -r requirements.txt +EXPOSE 8000 + +ENV DATABASE_URL="postgresql://postgres:postgresmaster@ymh-postgresql-0/test" + +CMD ["sh", "-c", "cd backend && uvicorn main:app --proxy-headers --host 0.0.0.0 --port 8000"] + diff --git a/homework/ymh-webapp/backend-deployment.yaml b/homework/ymh-webapp/backend-deployment.yaml new file mode 100644 index 0000000..16c8d87 --- /dev/null +++ b/homework/ymh-webapp/backend-deployment.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ymh-backend + namespace: ymh-webapp +spec: + replicas: 1 + template: + metadata: + labels: + app: ymh-backend + spec: + initContainers: + - name: ymh-initcontainer + image: ymh636/ymh-backend + command: ['sh', '-c', 'alembic upgrade head && python3 addUser.py'] + containers: + - name: ymh-backend + image: ymh636/ymh-backend + ports: + - containerPort: 8000 + selector: + matchLabels: + app: ymh-backend + diff --git a/homework/ymh-webapp/backend-service.yaml b/homework/ymh-webapp/backend-service.yaml new file mode 100644 index 0000000..2068447 --- /dev/null +++ b/homework/ymh-webapp/backend-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: ymh-backend + namespace: ymh-webapp +spec: + selector: + app: ymh-backend + type: NodePort + ports: + - protocol: TCP + port: 8000 + targetPort: 8000 + nodePort: 31426 + diff --git a/homework/ymh-webapp/frontend-Dockerfile b/homework/ymh-webapp/frontend-Dockerfile new file mode 100644 index 0000000..06c0507 --- /dev/null +++ b/homework/ymh-webapp/frontend-Dockerfile @@ -0,0 +1,13 @@ +FROM node:14 + +WORKDIR /app + +COPY . /app + +RUN npm install +RUN npm install -D tailwindcss + + +EXPOSE 3000 + +CMD ["npm", "run", "start"] diff --git a/homework/ymh-webapp/frontend-deployment.yaml b/homework/ymh-webapp/frontend-deployment.yaml new file mode 100644 index 0000000..428d5f4 --- /dev/null +++ b/homework/ymh-webapp/frontend-deployment.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ymh-frontend + namespace: ymh-webapp +spec: + replicas: 1 + template: + metadata: + labels: + app: ymh-frontend + spec: + containers: + - name: ymh-frontend + image: ymh636/ymh-frontend + ports: + - containerPort: 3000 + selector: + matchLabels: + app: ymh-frontend diff --git a/homework/ymh-webapp/frontend-service.yaml b/homework/ymh-webapp/frontend-service.yaml new file mode 100644 index 0000000..9377449 --- /dev/null +++ b/homework/ymh-webapp/frontend-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: ymh-frontend + namespace: ymh-webapp +spec: + selector: + app: ymh-frontend + type: NodePort + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 + nodePort: 31425 diff --git a/homework/ymh-webapp/helm.md b/homework/ymh-webapp/helm.md new file mode 100644 index 0000000..dad9df9 --- /dev/null +++ b/homework/ymh-webapp/helm.md @@ -0,0 +1,37 @@ +## Helm 裝 Postgres 我的作法 + +1. 在本地端裝postgres + + ```Shell + helm install ymh-postgresql-0 bitnami/postgresql --namespace ymh-webapp --set global.postgresql.auth.postgresPassword=postgresmaster --set global.postgresql.auth.password=postgresmaster --set global.postgresql.auth.username=postgres --set global.postgresql.auth.database=test + ``` + + 下面這兩個指令是要試連用的 + ```Shell + export POSTGRES_PASSWORD=$(kubectl get secret --namespace ymh-webapp ymh-postgres-postgresql -o jsonpath="{.data.postgres-password}" | base64 -d) + ``` + + ```Shell + kubectl run ymh-postgres-postgresql-client --rm --tty -i --restart='Never' --namespace ymh-webapp --image docker.io/bitnami/postgresql:16.1.0-debian-11-r9 --env="PGPASSWORD=$POSTGRES_PASSWORD" \ + --command -- psql --host ymh-postgres-postgresql -U postgres -d test -p 5432 + ``` + +2. 把本地端的檔案導出 + + ```Shell + helm get values > values.yaml + ``` + +3. 確認檔案是對的、並且接上遠端的kubeconfig,然後刪除本地端的 + + ```Shell + export KUBECONFIG=/Users/huangyoumei/poetry-demo/kubeconfig.yaml + helm uninstall + ``` +4. 部署到遠端 + + ```Shell + helm install -f values.yaml + ``` + + \ No newline at end of file