Ruby on Rails GKE Deploy Kit
Ruby on Rails GKE Deploy Kit. You can deploy your Ruby on Rails on Google Kubernate Engine with ingress https.
Dependency
- Google SDK https://cloud.google.com/sdk/docs
- Docker https://www.docker.com/
Installation
Add this line to your application's Gemfile:
gem "rails-gke"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install rails-gke
Configuration
Initialize Config
$ rails_gke_init
This command will create config/initializers/rails-gke.rb
Sample Config
# It's better to use ENV to define values.
Rails::Gke.configure do |config|
config.project_id = "elsoul"
config.app = "elsoul-api"
config.network = "elsoul-blog"
config.machine_type = "custom-1-6656"
config.zone = "asia-northeast1"
config.domain = "rails-gke.el-soul.com"
config.google_application_credentials = "config/credentials.json"
end
Check if configuration set in console
rails c
irb(main):002:0> Rails::Gke.configuration.nil?
=> false
Set your environment as needed above.
Then create yml
files in rails console
Rails::Gke::Initialize.create_yml
In console
rails c
irb(main):001:0> Rails::Gke::Initialize.create_yml
=> true
Now you can see 4 GKE yml files;
deployment.yml
service.yml
secret.yml
ingress.yml
In deployment.yml
you need to change your container version when you update your container.
asia.gcr.io/project_id/app_name:0.0.1
Also you need to set ENV.
And you can edit secret.yml
as you needed.
Then create rails task file
Rails::Gke::Initialize.create_task
In console
rails c
irb(main):001:0> Rails::Gke::Initialize.create_task
=> true
This will create lib/tasks/gke.rake
file.
Now you are ready to use all the command.
Usage
Set GCP Project
$ gcloud auth login
$ gcloud config set project `your-project-id`
Please check lib/tasks/gke.rake
file.
You can run gke command like this;
rails gke:TASK_NAME
So let's deploy your rails application on Google Kubernates Engine.
- Create VPC Network
rails gke:create_network
- Create Kubernate Cluster
rails gke:create_cluster
- Create Global IP
rails gke:create_ip
- Create namespace
rails gke:create_namespace
- Apply secret.yml
rails gke:apply_secret
- Apply deployment.yml
rails gke:apply_deployment
Check your GKE pods if its running well.
rails gke:get_pods
Output
NAME READY STATUS RESTARTS AGE
elsoul-api-deployment-5dfb777c67-456js 1/1 Running 0 20s
elsoul-api-deployment-5dfb777c67-g8kwp 1/1 Running 0 20s
elsoul-api-deployment-5dfb777c67-x857m 1/1 Running 0 20s
If you can't see containers ready, you need to fix your container first.
- Apply service.yml
rails gke:apply_service
Check your GKE svc if its running well.
rails gke:get_svc
Output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elsoul-api-service LoadBalancer xx.xxx.x.xx xx.xx.xxx.xxx 80:32321/TCP 1h
- Apply ingress.yml
rails gke:apply_ingress
Check your GKE ingress if its running well.
rails gke:get_ingress
This will take serveral mins. You need to set the IP address to A record in your domain management console once Ingress got IP ADDRESS
NAME HOSTS ADDRESS PORTS AGE
https-elsoul-api elsoul-api.el-soul.com xx.xx.xxx.xxx 80 5d16h
- Create LoadBalancer Frontend HTTPS
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/elsoul/rails-gke. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the Apache-2.0 License.
Code of Conduct
Everyone interacting in the HotelPrice project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.