05.1.Clouds‐GCP - yojulab/learn_DevOps GitHub Wiki

Google Cloud Platform(GCP)

Used Symbol mean
@ browser
~$ VM
~# docker in VM
> Another Terminal

create vm instance and than connect SSH in GCP

@ new project with ['test-myproject']
@ Compute Engine > VM instance with ['team-spring-mysql-fastapi-mongo'] (basic) > Disk size : 50G, Choose all with Firewall
@ click 'SSH' with 'team-spring-mysql-fastapi-mongo'
~$ sudo apt-get update && sudo apt install -y unzip docker-compose nginx certbot python3-certbot-nginx dnsutils nano vim

# /usr/local/bin에 Docker Compose 바이너리 다운로드
~$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
~$ sudo chmod +x /usr/local/bin/docker-compose
~$ docker-compose --version

~$ lscpu
~$ df -h
~$ sudo systemctl status nginx
~$ wget 127.0.0.1
@ http://[34.132.22.233]/

DNS management (need login) with extenal IP on vm instance GCP

  • [Optional]check name server (in case gabia)
@https://dns.gabia.com/ > get Domain 
> DNS Managerment ['cocolabhub.store']: Host - setup extenal IP with '@' and 'www' 

~$ nslookup cocolabhub.store
~$ nslookup www.cocolabhub.store

install Docker with containers in GCP

~$ sudo docker system prune

@ https://cocolabhub.com/teams/list > click button 'shell' to want it on list
~$ wget -O docker_files.zip http://cocolabhub.com/comodules/r/download/[6625f2935b8718ec133299dc]
~$ unzip docker_files.zip -d docker_folder && cd ./docker_folder
~/docker_folder$ sudo docker-compose build --no-cache
~/docker_folder$ sudo docker-compose --project-name teams_java_jupyterlab_mysql up -d

~$ sudo docker ps
~$ sudo docker exec -it [teams_java_jupyterlab_mysql_springboot_3.1.1_fastapi_1] bash

start fastapi server in docker

~# ps aux | grep uvicorn 
~# kill -9 [PID]
~# apt-get update && apt install -y nano
~# cd /apps/fastapis/app && nano .env
  ...
/apps/fastapis/app# cd ../ && git pull
/apps/fastapis# nohup uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 --workers 2 & 
/apps/fastapis# tail -f nohup.out 

outside_docker:~$ wget http://localhost:8000

start springboots server in docker

~# ps aux | grep gradlew 
~# kill -9 [PID]
~# cd /apps/springboots && nano ./src/main/resources/application.properties
  ...
server.address=0.0.0.0
  ...
spring.datasource.url=jdbc:mysql://[fastapi_spring-db_mysql_8-1]:3306/cocolang
  ...
remote.server.url=http://[cocolabhub.store]:80/images/
  ...
/apps/springboots# chmod +x ./gradlew && nohup ./gradlew bootRun & 
/apps/springboots# tail -f nohup.out 
/apps/springboots# exit

outside_docker:~$ wget http://localhost:8080

setup https certification and start nginx in GCP

~$ sudo certbot --nginx -d [cocolabhub.store] -d www.[cocolabhub.store]
~$ sudo rm /etc/nginx/sites-available/default
~$ sudo nano /etc/nginx/sites-available/default
    ...  # copy above refer source and then paste
~$ sudo nginx -t
~$ sudo systemctl restart nginx

@ https://cocolabhub.store/ -> springboot
@ https://www.cocolabhub.store/ -> springboot
@ http://www.cocolabhub.store:80/ -> fastapi
@ http://cocolabhub.store:80/images/empty.txt -> fastapi