0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

kindでIngressを使ってlocalhostからPodまでの疎通を確認する

Last updated at Posted at 2025-06-07

はじめに

Kubernetesを勉強しています。
Ingress、Service、Deployment、Podの役割は理解できたので、kindを使って実際に通信する環境を作ります。

作成する環境

localhost (http://localhost:80/) にアクセスするとIngress, Serviceを経て、Deploymentで作成したnginxのPodに疎通して応答を返します。
概要を図にまとめたものを以下に示します。

ingress.drawio.png

環境情報

Component Version
PC M1 MacBook Pro
OS macOS 15.5
Docker Desktop 4.42.0
kind v0.29.0
Kubernetes v1.33.1

kindでKubernetesクラスタを作成

kindでandbox-ingressというKubernetesクラスタを作成します。
このときにlocalhostの80番ポートをKubernetesクラスタにマッピングする必要があります。

manifestは以下です。

kind-sandbox-ingress.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: sandbox-ingress
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30080
    hostPort: 80
    protocol: TCP

このmanifestを元にkindコマンドでKubernetesクラスタを作成します。

kind create cluster --config kind-sandbox-ingress.yaml

ingress-nginxをdeployする

Ingressを使うためには、予めIngressControllerを準備する必要があります。
今回はingress-nginxを使用します。
helmでインストールします。

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm -n ingress-nginx install ingress-nginx ingress-nginx/ingress-nginx --create-namespace

ingress-nginx namspaceにingress-nginx関連リソースがデプロイされたことを確認します。

❯ k get all -n ingress-nginx

Ingress, Service, Deploymentを作成

Ingress, Service, Deploymentを作成するためのmanifestです。

ingress_svc_deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /
        pathType: Exact
        backend:
          service:
            name: nginx
            port:
              number: 30080

このmanifestをdeployします。

k apply -f ingress_svc_deploy.yaml

localhostからPodまでの疎通を確認

以下のURLにアクセスし、"Welcome to nginx!"と表示されれば成功です。
http://localhost:80/

スクリーンショット 2025-06-07 16.30.53.png

最後に

kindで作成したKubernetesクラスタにnginx IngressControllerをdeployし、Ingresss、Service、Deploymentを作成し、localhostからnginx podまでの疎通を確認することができました。

参考情報

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?