LoginSignup
15
9

More than 5 years have passed since last update.

Ingress でヘルスチェックのリクエスト先を変更する

Last updated at Posted at 2018-06-15

はじめに

  • GKE の Ingress ではヘルスチェックのためにデフォルトで GET / へリクエストを送信し、ステータスコード 200 が返ってくることを期待している。
  • このリクエスト先のパスを変更するには、Ingress のバックエンドのコンテナの readinessProbe を設定すれば良い。
    • 作成済みの Ingress のバックエンドの readinessProbe を変更した場合、リクエスト先の変更には時間がかかるので注意が必要。

設定例

  • 以下は素の Nginx の Deployment と Service と Ingress を立ち上げて、ヘルスチェック先を /healthcheck に変更する例。
deployment.yml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        readinessProbe:
          httpGet:
            path: /healthcheck
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
service.yml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx-service
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
  selector:
    app: nginx
ingress.yml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  backend:
    serviceName: nginx-service
    servicePort: 80
15
9
2

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
15
9