15
9

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.

GKE で予め作成しておいたマネージド証明書を使って https 通信を設定する

Last updated at Posted at 2019-05-07
apiVersion: networking.gke.io/v1beta1
kind: ManagedCertificate
metadata:
  name: example-certificate
spec:
  domains:
    - example.com

のように kind: ManagedCertificate を使うと k8s が GCP の Managed Certificate (Let's encrypt を使って証明書を発行して自動更新してくれるサービス)を作ってくれる。

ref. https://cloud.google.com/kubernetes-engine/docs/how-to/managed-certs

しかし、このやり方だとGCPのマネージドSSL証明書を k8s が作成することになり気持ち悪かった(個人の見解です)ので、予めマネージドSSL証明書をTerraformで作成して設定するようにしたメモ。

やり方

GCP で Managed Certificate を作っておく。terraform だとこんな感じ。

provider "google-beta" {
  project = "<project-name>"
}

resource "google_compute_managed_ssl_certificate" "api-cert" {
  provider = "google-beta"

  name = "api-cert"

  managed {
    domains = ["api.sslcert.tf-test.club"]
  }
}

あとは k8s で kind: Ingress の ingress.gcp.kubernetes.io/pre-shared-cert にあらかじめて作っておいた cert を指定する。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: api-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "api-ip"
    ingress.gcp.kubernetes.io/pre-shared-cert: "api-cert"
spec:
  backend:
    serviceName: api
    servicePort: 80
15
9
7

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?