πŸ›³ BE TIL Day 38 0504

JBΒ·2022λ…„ 5μ›” 4일
0

Backend02 Deploy

λͺ©λ‘ 보기
4/5

Main Note
https://docs.google.com/document/d/1mcjdlduwsKzc6dTi4p75fArpz7CQY8kQ67G1t2ndMQI/edit


πŸ‹ Service

create service for database
route :: [Kubernetes] --> [workload] --> my-database-02 --> click "expose"
port mapping 3006 : 3006
service type Cluster API
service name my-database-02

create service for backend
route :: [Kubernetes] --> [workload] --> my-backend-02 --> click "expose"
port mapping 3000 : 3000
service type load balancer
service name my-backend-02

  • After creating services, go to vscode --> app.module.ts file.
  • Change host to cluster IP, and change the tag.

    asia.gcr.io/wise-invention-347011/my-backend02:10
    ➀ Here, 10 is the tag
    (You can randomly set these tags)

After changing project files, re-build and re-push
docker compose -f docker-compose.prod.yaml build
docker compose -f docker-compose.prod.yaml push

πŸ”ΉTags


πŸ‹ Connect to Kubernetes Cluster via Cloud Shell

route :: [Kubernetes Engine] --> [Cluster] --> autopilot-cluster-02-1 --> {connect} --> [[ run in cloud shell ]]

(View all the pods that are currently working) >> kubectl get pod
(View deployment name) >> kubectl get deployment


kubectl set image deployment/my-backend-02 my-backend-02-256-1=my-backend-02-32524f342f]

kubectl set image deployment/[Operating deployment name] [Deployed image name]=[Image that is uploaded to cotainer registry]
➀ If this command is written, you don't have to deploy again every single time anymore. It will now automatically deploy. (re-operate this after re-deploying)

  • Operating deployment name is the name that appears when kubectl get deployment.
  • Deployed image name is the name that comes out from kubectl get pod -o yaml >> spec.containers.
  • Image that is uploaded to cotainer registry is from docker-compose.prod.yaml file --> services/my_backend/image

πŸ”Ή Check

kubectl get pods
kubectl logs [pod_name]
If this works well, [Kubernetes Engine] --> [service] --> my-backend-02's Endpoints
➀ With this endpoint, you can now access to playground.
Mine: 34.64.102.24:3000/graphql


πŸ‹ Connect DB with POD

1. Go to cloud SQL and copy your {private IP Address}.

2. Change the [vscode-->app.module.ts]'s host to private IP Address. Also, after changing the host, update the tag in `docker-compose.prod.yaml file`.

3. Then do build and push again to upload to "container registry".

Open cloud shell and connect to Kubernetes cluster.

  1. kubectl get pod -o yaml to check the image name first.
  2. kubectl set image deployment/[싀행쀑인 deployment λͺ…] [배포된 image name]=[cotainer registry에 λ“±λ‘λœ image]
  3. kubectl logs [pod name]
  4. Now you can remove the pod that regards database.
  5. Check wether it works well by commandingkubectl rollout restart deployment [deployment_name].
  6. After POD re-operates, dokubectl logs [pod name] and check the logs.

πŸ‹ Kubernetes Ingree SSL Authentication

Ingress : Cluster's Entrypoint

➀ Ingress balances traffic to the right route to service.

πŸ”Ή Upload Ingres and expose https

route :: [Kubernetes Engine] --> [Services and Ingress] --> check my-backend-02 (service) and click {create ingress}

External HTTP/S load balancer
Host and path rules >> Backends 1 : `my-backend-02`
Frontend configuration >> Protocol : HTTPS,
--> Create a new certificate >> name anything //  "create google-managed certificate"  // domain : jbeeshop.shop

Then go to Network Service > Cloud DNS > Change A redocr to Ingress IP Address


πŸ‹ JSON Secret File

JSON file connection

touch gcp-file-storage.json << create JSON file in pod
vi gcp-file-storage.json << fill up the JSON file
➀ i << insert mode
➀ insert the copied text from gcp-file-storage.json from vscode.
➀ esc and :wq to save and quit.
kubectl create secret << make this json file into secret mode.
kubectl create secret generic my-backend-secrets --from-file=gcp-file-storage.json=./gcp-file-storage.json << create
kubectl get secrets << view

Afterall, edit vscode > file.service.ts > keyFilename to 'my-secret/gcp-file-storage.json'.
➀ Do build and push again in vscode.
Cloud shell : kubectl set image deployment/my-backend-02 my-backend02-sha256-1=asia.gcr.io/wise-invention-347011/my-backend02:11

Then go back to GCP and go to Kubernetes Engine > Workload > my-backend-02
Click YAML and edit yaml like this:

Then go to postman and request image upload API to check wether the image successfully saves to the storage.


profile
두비두λ°₯λ°₯

0개의 λŒ“κΈ€