Skip to content

Instantly share code, notes, and snippets.

@cesartalves
Last active April 13, 2021 09:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesartalves/19c37e4fd799c07bef3ec10999487208 to your computer and use it in GitHub Desktop.
Save cesartalves/19c37e4fd799c07bef3ec10999487208 to your computer and use it in GitHub Desktop.
Rails Conf k8s quick setup
# https://github.com/ddollar/forego
ASSET_HOST=localhost:3000
APPLICATION_HOST=localhost:3000
BCRYPT_COST=12
PORT=3000
RACK_ENV=development
RACK_MINI_PROFILER=0
SECRET_KEY_BASE=development_secret
EXECJS_RUNTIME=Node
RAILS_MIN_THREADS=2
RAILS_MAX_THREADS=5
SMTP_ADDRESS=smtp.example.com
SMTP_DOMAIN=example.com
SMTP_PASSWORD=''
SMTP_USERNAME='email@example.com'
WEB_CONCURRENCY=1
WEBPACKER_DEV_SERVER_PORT=3035
WEBPACKER_DEV_SERVER_HOST=localhost
WEBPACKER_DEV_SERVER_PUBLIC=localhost:3035
REDIS_URL=redis://127.0.0.1:6379/15
DATABASE_URL=postgresql://postgres:password@127.0.0.1:5432/link
## These will be put in place in Lab 1
# postgresql://postgres@172.16.100.20:5432/link
# REDIS_URL=redis://172.16.100.20:6379/15
services:
db:
image: postgres
ports:
- "5432:5432"
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: link
redis:
image: redis
ports:
- 6379:6379
# SETTING UP DATASTORES (PGSQL / REDIS)
## PGSQL
# generate database dump
brew services start postgresql
rake db:setup
pg_dump link_development > ../deploying-rails-to-kubernetes/vagrant/data/link_development.sql
# ssh onto datastores vm
vagrant ssh workshop_datastores
sudo su - postgres
cd /vagrant/data
psql
create database link;
\c link
exit;
psql link < link_development.sql
exit
sudo vim /etc/postgresql/12/main/postgresql.conf on workshop_datastores
# add this
listen_addresses = '*'
sudo vim /etc/postgresql/12/main/pg_hba.conf
# add this without the comments
# host all all 172.16.100.1/32 trust
# host all all 172.16.100.10/32 trust
sudo service postgresql restart
## REDIS
sudo vim /etc/redis/redis.conf
# add bind and chang protected-mode to "noo"
bind 172.16.100.20
protected-mode no
sudo service redis restart
## SETTING UP APPLICATION
## ssh onto k8s vm
vagrant ssh workshop_microk8s
sudo apt-get install docker.io
git clone https://github.com/base10/link
sudo docker build -t link-container . -f deploy/Dockerfile
sudo docker images
sudo docker save link-container:latest > ~/link-container.tar
microk8s ctr images ls | grep link
microk8s ctr image import ~/link-container.tar
microk8s ctr images ls | grep link
kubectl apply -f deploy/k8s/
kubectl get all --all-namespaces
kubectl scale --replicas=2 deployment.apps/link-app
kubectl scale --replicas=1 deployment.apps/link-app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment