Я собираюсь использовать GKE для создания контейнеров с rubyonrails,
Я хочу сделать db: create и db: migrate автоматически
Dockerfile сделан таким образом
Dockerfile
FROM ruby: 2.4.1-alpine
RUN apk update && apk upgrade && apk add --update - no - cache bash alpine - sdk tzdata postgresql - dev nodejs
RUN mkdir / app
WORKDIR / app
ADD Gemfile / app / Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN bundle install - path vendor / bundle
ADD. / App
RUN bundle exec rake assets: precompile
RUN chmod + x /app/post-start.sh
EXPOSE 3000
Настройка db: create и db: migrate
/app/post-start.sh
#!/bin/bash
RAILS_ENV = $ RAILS_ENV bundle exec rake db: create
RAILS_ENV = $ RAILS_ENV bundle exec rake db: migrate
Это развертывание
rails.yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: rails
labels:
app: rails
spec:
replicas: 1
selector:
matchLabels:
app: rails
template:
metadata:
labels:
app: rails
spec:
containers:
- image: asia.gcr.io/balmy-geography-216916/railsinitpg:v1
name: rails
env:
- name: RAILS_ENV
value: "production"
- name: DATABASE_HOST
value: postgresql
- name: DATABASE_USERNAME
valueFrom:
secretKeyRef:
name: rails
key: database_user
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: rails
key: database_password
- name: SECRET_KEY_BASE
valueFrom:
secretKeyRef:
name: rails
key: secret_key_base
- name: DATABASE_PORT
value: "5432"
lifecycle:
postStart:
exec:
command:
- /bin/bash
- -c
- /app/post-start.sh
ports:
- containerPort: 3000
name: rails
command: ["bundle", "exec", "rails", "s", "-p", "3000", "-b", "0.0.0.0"]
kubectl create -f /kubernetes/rails.yml
Я сделал это
Ошибки - Содержание
error: valid validating "STDIN": error validating data: ValidationError (Deployment.spec.template.spec.containers [0]): unknown field "postStart" in io.k8s.api.core.v1.Container; if you choose to ignore these errors, turn validation off with --validate = false
Указанная ошибка перестала существовать, но снова возникла ошибка
Warning FailedPostStartHook 5m1s (x4 over 5m49s) kubelet, gke-cluster-1-default-pool-04b4ba0b-680k Exec lifecycle hook ([/bin/bash -c /app/post-start.sh]) for Container "rails" in Pod "rails-5c5964445-6hncg_default(1d6a3479-1fcc-11e9-8139-42010a9201ec)" failed - error: command '/bin/bash -c /app/post-start.sh' exited with 126: , message: "rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\\"/bin/bash\\\": stat /bin/bash: no such file or directory\"\n\r\n"
Исправить Dockerfile
Исправлено Deployment.yml
Это было хорошо.
Большое спасибо.