Skip to content

ingress-nginxでhttpbinサーバーを公開する

Posted on:April 20, 2024 at 08:10 AM

kubernetesのingress-nginxを使ってhttpbinを外部公開する

kubernetes自体の構成については以下を参照

helmを使いながらのkubernetesのセットアップ
kubernetesのセットアップ方法を書いています。使っている技術スタック istio metallb calico helm
helmを使いながらのkubernetesのセットアップ favicon https://blog.tosukui.xyz/posts/re-kubernetes-setup
helmを使いながらのkubernetesのセットアップ

httpbinサービスのmanifest

deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpbin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpbin
      version: v1
  template:
    metadata:
      labels:
        app: httpbin
        version: v1
    spec:
      serviceAccountName: httpbin
      containers:
      - image: docker.io/kennethreitz/httpbin
        name: httpbin
        ports:
        - containerPort: 80

ingress(ingress nginx用)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-httpbin
spec:
  rules:
  - host: httpbin.hogehoge.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: httpbin
            port:
              number: 80
  ingressClassName: nginx

service account

apiVersion: v1
kind: ServiceAccount
metadata:
  name: httpbin

service

apiVersion: v1
kind: Service
metadata:
  name: httpbin
  labels:
    app: httpbin
    service: httpbin
spec:
  ports:
  - name: http
    port: 8000
    targetPort: 80
  selector:
    app: httpbin

## クラスタに適用する 上記をhttpbinディレクトリに入れて、以下のコマンドで適用

kubectl apply -f httpbin -n httpbin

確認

kubectl get pod httpbin -n httpbin

ブラウザでhttpbin.hogehoge.comを確認する