Help us understand the problem. What is going on with this article?

GKEで helm + nginx-ingress を使う

前提条件

  • クラスタをすでに構築済み
  • kubectlが使える
  • helm install でchatを配置可能
  • gcloud auth済み
  • kubernetesのnamespaceはdefaultを使用
  • tlsは作成済み(tlsはなくても動作します。)

1. サンプルappをgcrにpush

※説明のため筆者の公開しているサンプルイメージをダウンロードしています。適時書き換えてください。

$ docker push newsdict/rust:v0.0.1
$ docker tag newsdict/rust:v0.0.1 docker gcr.io/newsdict-217812/docker_rust:v0.0.1
$ docker push gcr.io/newsdict-217812/docker_rust:v0.0.1

2. podとserviceを配置

※このセクションはモックを配置するだけなので適時書き換えてください

kubectl を使いserviceとpodを作成します。(1ファイルに書いてますが、分けても大丈夫です)

sample-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: docker-rust-service
  labels:
    name: docker-rust-service
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 3000
  selector:
    app: docker-rust
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-rust
spec:
  replicas: 1
  revisionHistoryLimit: 1
  selector:
    matchLabels:
      app: docker-rust
  template:
    metadata:
      labels:
        app: docker-rust
    spec:
      containers:
      - name: master
        image: gcr.io/newsdict-217812/docker_rust:v0.0.1
        workingDir: /rust
        resources:
          requests:
            cpu: 50m
            memory: 50Mi
        ports:
        - containerPort: 3000
        readinessProbe:
          httpGet:
            path: /
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 30
          timeoutSeconds: 5

配置

$ kubectl apply -f sample-service.yaml

3. helmでnginx-ingressをインストール

static ipの作成

gcloud compute addresses create docker-rust-static-ip

install

$ helm install --name nginx-ingress stable/nginx-ingress --set rbac.create=true --set controller.service.loadBalancerIP=xxx.xxx.xxx.xxx

※xxx.xxx.xxx.xxxのところは作ったstatic-ipに書き換えてください
※--set rbac.create=trueはrbacを使っている時だけのオプションなので適時消すなりしてください

確認

以下で作成が完了したことを確認してください。

$ kubectl get service nginx-ingress
$ kubectl get pods |grep nginx

4. ingressを配置

ingress.yml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: docker-rust-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: example-rust.newsdict.io
      http:
        paths:
          - backend:
              serviceName: docker-rust-service
              servicePort: 3000
            path: /
  tls:
    - hosts:
        - example-rust.newsdict.io
      secretName: docker-rust-tls

適用

$ kubectl apply -f ingress.yml

5. ipの確認

nginx-ingressでは $kubectl get ingress で見えるIPは使えない、serviceに配置されているLoadBalancerのIPを使う必要があります。

$ kubectl get service | grep nginx-ingress-controller

上記に表示されるEXTERNAL-IPをDNSなどに紐づければnginx-ingressの導入完了です

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away