3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

traefik on Kubernetesでtraefikをリバースプロキシとして使用する

Last updated at Posted at 2018-05-15

この記事の内容

  • traefikをKubernetes上でKubernetesモードではなくただのリバースプロキシとして利用するときの設定例を書きます
  • traefikのBasics (https://docs.traefik.io/basics/) や Configuration/Commons (https://docs.traefik.io/configuration/commons/) を読んでも「こうすれば動く」という設定例をフルで書いてなくてハマってしまったので自分用メモとしての意味も込めています

deploymentの設定

以下のような設定でdeploymentを定義します

  spec:
      containers:
      - image: traefik:alpine
        name: traefik-rproxy
        resources:
          limits:
            cpu: 0.1
            memory: 128Mi
        command:
        - "sh"
        - "-c"
        - "traefik"

traefikの設定

リバースプロキシとしてtraefikを動かすためのtomlは以下のようになります

apiVersion: v1
kind: ConfigMap
metadata:
  name: traefik-rproxy-config
data:
  traefik.toml: |
    defaultEntryPoints = ["http","https"]
    logLevel = "INFO"

    [file]
    [entryPoints]
      [entryPoints.http]
      address = ":80"

      [entryPoints.https]
      address = ":443"


    [frontends]
      [frontends.some_frontend]
      entrypoints = ["http"]
      backend = "some_backend"

    [backends]
      [backends.some_backend]
        [backends.some_backend.servers.some_service_name]
        passHostHeader = true
        weight = 1
        url = "http://some-other-service:80"

    [accessLog]
    format = "json"
    filePath = "/mnt/log/access.log"

設定のポイント

  • [file]はfileでforntend/backendの設定を行う際には必須
  • passHostHeader = trueにしないとHostヘッダーを切られてしまうので構成によってはハマりどころになります
  • some_frontend,some_backend,some_service_nameは任意の名前にしてOK
  • ロードバランシング方法を記載しないと、デフォルトロードバランシングはwrrになるので、weight=Nの設定が必須
    • wrrとは Weighted Round-robin
    • デバッグログを出力すると以下のようにデフォルトで設定されていることがわかります
time="2018-05-14T11:13:52Z" level=debug msg="Validation of load balancer method for backend backend1 failed: invalid load-balancing method ''. Using default method wrr."
3
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?