11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Nginx Ingress インストール

Last updated at Posted at 2020-04-24

概要

  • k8sテスト環境構築

    Nginx Ingress インストール

構築目次

環境

  • Rancher: v2.6.3
  • kubernetes(Client): v1.22.4
  • kubernetes(Server): v1.22.4
  • Nginx Ingress Chart: v4.0.13
  • Nginx Ingress App: v1.1.0

インストール

helmにingress repo追加

$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm repo update

## 確認 ##
$ helm search repo ingress-nginx/ingress-nginx
NAME                       	CHART VERSION	APP VERSION	DESCRIPTION                                       
ingress-nginx/ingress-nginx	4.0.13       	1.1.0      	Ingress controller for Kubernetes using NGINX a...

helmでNginx Ingress インストール

## namespace(ingress-system) 作成
$ kubectl create ns ingress-system
namespace/ingress-system created

## 「ingress-nginx/ingress-nginx」を指定名前(nginx-ingress)で指定namespace(ingress-system)にインストール
## ssl passthrough を使うため、「--set controller.extraArgs.enable-ssl-passthrough=""」追加
$ helm install obi-test ingress-nginx/ingress-nginx -n ingress-system --set controller.extraArgs.enable-ssl-passthrough=""

## ssl passthrough 設定が不要の場合は以下だけで良い。
$ helm install obi-test ingress-nginx/ingress-nginx -n ingress-system

## インストール後、確認
$ helm list -n ingress-system
NAME    	NAMESPACE     	REVISION	UPDATED                                	STATUS  	CHART               	APP VERSION
obi-test	ingress-system	1       	2021-12-29 18:16:08.703864046 +0900 JST	deployed	ingress-nginx-4.0.13	1.1.0


$ kubectl get all -n ingress-system
NAME                                                     READY   STATUS    RESTARTS   AGE
pod/obi-test-ingress-nginx-controller-7b47d89bcb-srbfw   1/1     Running   0          2m3s

NAME                                                  TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/obi-test-ingress-nginx-controller             LoadBalancer   10.43.58.216    <pending>     80:30769/TCP,443:30528/TCP   2m3s
service/obi-test-ingress-nginx-controller-admission   ClusterIP      10.43.146.222   <none>        443/TCP                      2m3s

NAME                                                READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/obi-test-ingress-nginx-controller   1/1     1            1           2m3s

NAME                                                           DESIRED   CURRENT   READY   AGE
replicaset.apps/obi-test-ingress-nginx-controller-7b47d89bcb   1         1         1       2m3s


$ kubectl get svc -n ingress-system
NAME                                          TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
obi-test-ingress-nginx-controller             LoadBalancer   10.43.58.216    <pending>     80:30769/TCP,443:30528/TCP   22m
obi-test-ingress-nginx-controller-admission   ClusterIP      10.43.146.222   <none>        443/TCP                      22m

動作確認

  • マニフェスト作成
test-ingress.yaml
---
### Ingress 作成
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  ingressClassName: nginx
  rules:
  - host: nginx.test.local
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-svc
            port:
              number: 80
---
### Service 作成
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  selector:
    app: nginx
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
---
### Pod 作成
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.21.4
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
  • マニフェスト適用
$ kubectl apply -f test-ingress.yaml
  • hosts 設定追加
    Node IP(Master, Worker node中1個)とIngressで設定したhostを紐づけ
$ cat /etc/hosts
........
192.168.245.102 nginx.test.local
........
  • NodePort 確認
    nginx-ingress-controllerのNodePortを確認(ここでは「30769」)
$ kubectl get svc -n ingress-system
NAME                                          TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
obi-test-ingress-nginx-controller             LoadBalancer   10.43.58.216    <pending>     80:30769/TCP,443:30528/TCP   22m
obi-test-ingress-nginx-controller-admission   ClusterIP      10.43.146.222   <none>        443/TCP                      22m
  • 接続確認
$ curl -I http://nginx.test.local:30769
HTTP/1.1 200 OK
.........
11
12
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
11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?