Я сделал свой проект с рельсами + mysql + vue. js + webpacker.
Затем я сделал Dockerfile
и docker-compose.yml
, чтобы я мог запустить его в localhost.
Теперь я хочу развернуть их с K8s, но у меня проблема с Job в K8s. На самом деле, я впервые работаю с K8s, поэтому, если что-то отсутствует или что-то не так, пожалуйста, дайте мне знать, что мне нужно сделать. Вот мой Dockerfile и ymls.
ps. khjoo19/line-manager:v1
- это мое docker изображение, загруженное в docker хаб.
Dockerfile
FROM ruby:2.5.5
ENV LANG C.UTF-8
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs && \
curl -sL https://deb.nodesource.com/setup_7.x | bash - && \
apt-get install nodejs
RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn && \
gem install bundler
WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT [ "entrypoint.sh" ]
ENV APP_HOME /line_manager
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
COPY . /line_manager
RUN yarn upgrade
docker -compose.yml
version: '3'
services:
db:
image: mysql:5.7
environment:
DB_USER: root
DB_ROOT_PASSWORD: password
DB_PASSWORD: password
DB_HOST: db
webpacker:
build: .
command: bundle exec bin/webpack-dev-server
volumes:
- .:/line_manager
ports:
- "8080:8080"
web:
build: .
command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/line_manager
environment:
DB_USER: root
DB_ROOT_PASSWORD: password
DB_PASSWORD: password
DB_HOST: db
RAILS_ENV: development
ports:
- "3000:3000"
depends_on:
- db
- webpacker
tty: true
stdin_open: true
mysql .yml (K8s)
apiVersion: v1
kind: Service
metadata:
namespace: line-manager
name: db
labels:
app: web
spec:
selector:
app: web
clusterIP: None
ports:
- port: 3306
---
kind: PersistentVolume
apiVersion: v1
metadata:
namespace: line-manager
name: db-pv
labels:
app: web
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
storageClassName: standard
hostPath:
path: "/tmp/mysql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: line-manager
name: db-pvc
labels:
app: web
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: standard
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: line-manager
name: db
labels:
app: web
spec:
selector:
matchLabels:
app: web
strategy:
type: Recreate
template:
metadata:
labels:
app: web
spec:
containers:
- name: mysql
image: mysql:5.7.17
envFrom:
- configMapRef:
name: rails-config
ports:
- containerPort: 3306
name: db
volumeMounts:
- name: db-pv
mountPath: /var/lib/mysql
volumes:
- name: db-pv
persistentVolumeClaim:
claimName: db-pvc
rails-config.yaml (K8s)
apiVersion: v1
kind: ConfigMap
metadata:
namespace: line-manager
name: rails-config
data:
RAILS_ENV: 'development'
DB_HOST: 'db'
DB_USER: 'root'
DB_ROOT_PASSWORD: 'password'
DB_PASSWORD: 'password'
rails-job.yaml (K8s)
apiVersion: batch/v1
kind: Job
metadata:
namespace: line-manager
name: web-job
labels:
app: web
spec:
template:
metadata:
namespace: line-manager
name: web-job
labels:
app: web
spec:
containers:
- name: web-job
image: khjoo19/line-manager:v1
imagePullPolicy: Always
command: ["/bin/sh"]
args: ["-c", "bundle exec rake db:create && bundle exec rake db:migrate"]
envFrom:
- configMapRef:
name: rails-config
restartPolicy: Never