We can run an application developed with Net Core on Windows, Linux, and Mac systems. In this article we will publish an application developed with Net Core 2.1 version on Ubuntu 16.04 using nginx.
It is pretty easy but there is no good documentation on internet. I want to write an article about this. Here are my steps to deploy .net core application on google cloud! Thanks for reading..
Deploying .Net Core App on Google Cloud (ubuntu)
- Create Ubuntu instance from Google Cloud
- Ubuntu 18.04 LTS version
- Set firewall rules to instance’s Network Tags (Following tags should be exist in the Google Cloud “Network Services/Firewall Rules”)
- http-server
- https-server
- default-allow-ssh
- vnc-server (if you want RDP)
- Install google cloud sdk – https://cloud.google.com/sdk (cloud sdk should install to the developer PC)
- use “Google Cloud SDK Shell”
- Login gcloud
- gcloud auth login
- Open ssh console
- gcloud compute ssh YOUR_INSTANCE_NAME –project YOUR_PROJECT_NAME –zone europe-west4-a –ssh-flag “-L 22:localhost:22”
- File transfer to ubuntu pc
- gcloud compute scp C:\Users\YOURNAME\Desktop\publish\*.* YOUR_INSTANCE_NAME —
YOUR_PROJECT_NAME —YOUR_ZONE (example: zone europe-west4-a)
- gcloud compute scp C:\Users\YOURNAME\Desktop\publish\*.* YOUR_INSTANCE_NAME —
- Install .Net Core SDK and Runtime to the Ubuntu 18.04 instance
- Update Ubuntu
- sudo apt-get update
- sudo apt-get upgrade
- Install .net core package
- “Go to user folder for permisson (like /home/ YOUR_NAME)”
- wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
- sudo dpkg -i packages-microsoft-prod.deb
- sudo add-apt-repository universe
- sudo apt-get install apt-transport-https
- sudo apt-get update
- sudo apt-get install dotnet-sdk-2.1
- “check .net core installed”
- dotnet –version
- Update Ubuntu
- Set firewall settings
- sudo ufw enable
- sudo ufw allow https
- sudo ufw allow ssh
- sudo ufw allow http
- Create Folder on Ubuntu Instance
- sudo mkdir YOUR_FOLDER_NAME
- sudo chown YOUR_NAME YOUR_FOLDER_NAME
- Copy project files to instance (in the Google Cloud SDK Command Line Toot, not ubuntu shell)
- gcloud compute scp C:\ProjectFolder\*.*
YOUR_INSTANCE_NAME –project
YOUR_PROJECT_NAME –zone YOUR_ZONE
- gcloud compute scp C:\ProjectFolder\*.*
- Create .ppk file
- you need to create .ppk file with PuTTY Key Generator
- Create a .ppk file with a same name with the instance of linux machine. For Example; your linux machine name: sample-ubuntu, and your .ppk file name must be ‘sample-ubuntu.ppk’
- Key Comment: Your sample-ubuntu machine user name
Key passphrase: Your password& save private key as sample-ubuntu.ppk
- Create sh file (yourproject.sh file in the Your publish folder)
#! /bin/sh
sudo dotnet /YourProject/YourProject.dll
- Create service file (yourproject.service file in the Your publish folder)
[Unit]
Description= yourproject daemon service
After=basic.target syslog.target network.target
[Service]
ExecStart=/ YourProject/yourproject.sh
Restart=always
StandardOutput=syslog
StandardError=inherit
SyslogFacility=daemon
SyslogLevel=err
SyslogIdentifier=yourproject
[Install]
WantedBy=multi-user.target
- Set permission
- sudo chmod +x YourProject.dll
- sudo chmod +x yourproject.sh
- Copy service file to linux system folder
- sudo cp yourproject.service /lib/systemd/system
- Reload SystemD and enable the service
- sudo systemctl daemon-reload
- sudo systemctl enable yourproject
- Start service
- sudo systemctl start yourproject
- sudo systemctl stop yourproject
- sudo systemctl start yourproject
- View service status
- systemctl status yourproject
Your application is now running on your linux machine. You can check your server by entering the IP address of your server. The service definition file that we created will start automatically even when our server restarts or the dotnet runtime collapses.
As you, if you can follow steps deploying .net core app on google cloud, it is so easy.
you can ask every thing to us from instagram.com/DeveloperKafasiOfficial