LoginSignup
54
43

More than 3 years have passed since last update.

Ingressにstatic-ipを指定してやった on GKE and GCE

Last updated at Posted at 2017-05-19

GKEとGCEのIngressではGCPで予約したstatic-ipをNameで指定出来ます。
ちなみに何も指定しないでIngressを作ると毎回IPが変わります。

なぜstatic-ipを振るのか

IngressのIPにドメインを振ってる場合に毎回IPが変わるとかなり辛いため。

手順

  • static-ipを予約する
  • 予約したstatic-ipを指定してingressを作る
  • 予約したstatic-ipがingressに振られているか確認

準備

gcloudのコマンドがどのプロジェクトにセットされているかを確認

gcloud config get-value project

以前、Ingressを作りたいプロジェクトとは違うプロジェクトがセットされていて
Ingressを作り直しても予約したはずstatic-ipが使われずに辛い思いをしました・・・

もし違うプロジェクトがsetされていれば

gcloud config set project {project-name}

1. static-ipを予約する

gcloud コマンドでstatic-ipを予約。
予約するのはIPのタイプはグローバルです。
ちなみにGCPのコンソールからも出来ます。

gcloud compute addresses create test-ip --global

ちゃんとcreateできていれば、listに追加されてます。予約しただけなのでSTATUSはRESERVEDのはずです。

gcloud compute addresses list --global
NAME                     REGION  ADDRESS          STATUS
test-ip                          35.186.221.137   RESERVED

2. 予約したstatic-ipを指定してingressを作る

kubernetes.io/ingress.global-static-ip-name: "test-ip"

を追加したingress.yamlを指定してcreateする。

kubectl create -f ingress.yaml

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: static-ip
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "test-ip"
spec:
  tls:
  # This assumes tls-secret exists.
  - secretName: tls-secret
  backend:
    # This assumes http-svc exists and routes to healthy endpoints.
    serviceName: http-svc
    servicePort: 80

3. 予約したstatic-ipがingressに振られているか確認

$ kubectl get ing
NAME           HOSTS     ADDRESS         PORTS     AGE
test-ingress   *         35.186.221.137   80, 443   1h

$ gcloud compute addresses list --global
NAME                     REGION  ADDRESS          STATUS
test-ip                          35.186.221.137   IN_USE

参考

ほとんど、このリンクからの引用です!
https://github.com/kubernetes/ingress/tree/master/examples/static-ip/gce

54
43
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
54
43