LoginSignup
3
0

More than 5 years have passed since last update.

Phoenix on GKE

Last updated at Posted at 2019-01-20

PhoenixをGKEで動かせるようにした。
本番リリースとかとは違って漸進的に動作確認しながら開発を進行したかったのでなるべく本番環境に近い環境&&コスト抑えめを実現するためにいろいろ考えた

構成

GKE上に構築
* Phoenix(何も考えずにインスタンスを借りると定価で請求されちゃうのでプリエンプティブノードで立ててる)

GCE上に構築
* Postgres(普通にインスタンスを借りると高いのでUSリージョンでf1-microの無料枠で立ててる)

通信周り
* ingress(通信周りはどうしようもないので定価で請求されちゃう(´・ω・`))

とりあえずこんな感じ

Dockerfile

コンテナビルドするときに使ったDockerfile
実は MIX_ENV=prodにするとアセットが読み込まれなくてどうしたらいいかかなり悩んだ。
npm i && node node_modules/brunch/bin/brunch buildが大切だった


FROM elixir:1.7.4-alpine

WORKDIR /app

RUN apk add --update nodejs nodejs-npm

RUN mix local.hex --force && \
  mix archive.install --force https://github.com/phoenixframework/archives/raw/master/phx_new.ez && \
  mix local.rebar --force

COPY . .

RUN mix deps.get

RUN cd assets && \
  npm i && \
  node node_modules/brunch/bin/brunch build

RUN mix compile
RUN mix phx.digest

CMD ["mix", "phx.server"]

deployment

マニフェストはkompose使ってdocker-compose.ymlをコンバートしたものを改造してる感じ
Phoenixはステートレスをキープするのでボリュームのマウントとかはしない。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: web-server
  name: web-server
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: web-server
    spec:
      containers:
        - image: gcr.io/GCP_PROJECT/web_server
          imagePullPolicy: Always
          name: web-server
          command:
            - "mix"
            - "phx.server"
          ports:
            - containerPort: 4000
              name: web-server
          envFrom:
            - configMapRef:
                name: web-server
          readinessProbe:
            httpGet:
              port: 4000
              path: /health_check

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0