Skip to content

Ingress 構築手順

クラスタ外部からの HTTP/HTTPS 通信を制御する Ingress の構築および動作確認手順です。

参考文献

手順

サンプルとして、/sample/greetおよび/sample/byeエンドポイントを用意したアプリをデプロイすることを想定します。

リソース作成

  • Ingress Controller をインストールします:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.13.2/deploy/static/provider/cloud/deploy.yaml
  • Ingress リソースを作成します:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sample-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
          - pathType: Prefix
            path: /sample
            backend:
              service:
                name: sample-service
                port:
                  number: 8080
  • Service および Deployment を作成します:
kind: Service
apiVersion: v1
metadata:
  name: sample-service
spec:
  type: NodePort
  selector:
    app: sample
  ports:
    - port: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-deploy
  labels:
    app: sample
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sample
  template:
    metadata:
      labels:
        app: sample
    spec:
      containers:
        - name: sample
          image: nobexample/easyapp:latest
          ports:
            - containerPort: 8080
  • 他端末からの疎通を通せるようにingress-nginxを修正します:
kubectl patch svc ingress-nginx-controller -n ingress-nginx -p '{"spec": {"externalTrafficPolicy": "Cluster"}}'

動作確認

  • Ingress が待ち受けているポートを確認します:
kubectl get svc ingress-nginx-controller -n ingress-nginx
  • curl で疎通確認をとります:
$ curl localhost:31579/sample/greet
Hello, World!

$ curl localhost:31579/sample/bye
GoodBye, World!