LoginSignup
4
4

More than 1 year has passed since last update.

Amazon EKSでNGINX Ingress Controllerを利用する

Last updated at Posted at 2022-10-22

はじめに

Amazon EKSでNGINX Ingress Controllerを利用する方法をまとめます。
Mac環境を想定しています。
NGINX Ingress Controllerは、NGINXをリバース プロキシおよびロード バランサーとして使用する Kubernetes 用のイングレス コントローラーです。
NGINX Ingress Controllerを利用するとCLBが構築されます。

実行環境の準備

  1. AWS CLIの設定
    AWS CloudFormationを動かすためのAWS CLIの設定を参考にしてください。

  2. EKSクラスタの構築
    Macでeksctlを利用してAmazon EKSのクラスターを構築するを参考にしてください。

  3. EKSのコンテキストの設定
    MacにてAmazon EKSの設定をするを参考にしてください。

  4. Helmの設定
    Amazon EKSでHelmを利用するを参考にしてください。

環境設定

  1. NGINX Ingress ControllerのチャートをHelmでインストールする
    ※事前にKubernetesクラスターのコンテキストの設定をします。

    # ingress-nginx チャートリポジトリを追加する
    helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
    
    # リポジトリを更新する
    helm repo update
    
    # NGINX Ingress Controller のチャートをインストールする
    helm install nginx-ingress-controller ingress-nginx/ingress-nginx \
      -n nginx-ingress-controller \
      --create-namespace
    
    # NGINX Ingress Controller がインストールされたことを確認する
    helm list -n nginx-ingress-controller
    

[サンプル] guestbookのマニフェスト

guestbookを構築する。

  1. guestbook をクラスターに適用する

    kubectl apply -f https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-deployment.yaml
    
  2. ingress.yaml を作成する

    ingress.yaml
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        kubernetes.io/ingress.class: nginx
      name: guestbook-ui
      namespace: default
    spec:
      rules:
      - http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: guestbook-ui
                port:
                  number: 3000
    
  3. service.yaml を作成する
    guestbook-ui-svc.yaml を参考にする

    service.yaml
    apiVersion: v1
    kind: Service
    metadata:
      annotations:
      labels:
        app: guestbook-ui
      name: guestbook-ui
      namespace: default
    spec:
      ports:
      - port: 3000
        protocol: TCP
        targetPort: 80
      selector:
        app: guestbook-ui
      type: NodePort
    
  4. クラスターに適用する

    kubectl apply -f ingress.yaml
    kubectl apply -f service.yaml
    
  5. guestbook にアクセスする
    ※ELBが構築されるまで、数分アクセスできないことがあります。

    open "http://$(kubectl get svc -n nginx-ingress-controller nginx-ingress-controller-ingress-nginx-controller | awk '{ print $4 }' | tail -1)"
    

クリーンアップ

  1. クラスターから削除する

    kubectl delete -f ingress.yaml
    kubectl delete -f service.yaml
    
  2. guestbook をクラスターから削除する

    kubectl delete -f https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-deployment.yaml
    
  3. NGINX Ingress ControllerをHelmで削除する

    helm delete nginx-ingress-controller -n nginx-ingress-controller
    
  4. Namespaceを削除する

    kubectl delete ns nginx-ingress-controller
    
4
4
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
4
4