Pembaharuan Halaman
2022 Juni 08:
- Versi ingress-nginx controller v1.2.0
- Menambahkan langkah membuat ingress class
Prasyarat
- Kubernetes Cluster
Panduan
- Terapkan manifest yang disediakan pada website nginx
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.0/deploy/static/provider/baremetal/deploy.yaml
- Sunting service
ingress-nginx-controller
pada namespaceingress-nginx
Isikan dengan IP Node kubernetes yang akan melayani request
kubectl -n ingress-nginx edit svc ingress-nginx-controller
Tambahkan baris berikut
spec:
externalIPs:
- <IP_NODE_1>
- <IP_NODE_2>
- <IP_NODE_N>
- Buat ingress class
cat<<EOF > ingressclass.yaml
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
labels:
app.kubernetes.io/component: controller
name: nginx
annotations:
ingressclass.kubernetes.io/is-default-class: "true"
spec:
controller: k8s.io/ingress-nginx
EOF
kubectl apply -f ingressclass.yaml
- Jalankan aplikasi contoh
# Buat deployment
kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
# Buat service
kubectl expose deployment web --port=8080
# Buat ingress
cat<<EOF > web-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: example.id
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
EOF
kubectl apply -f web-ingress.yaml
# Uji coba
# Contoh: curl --resolve 'example.id:80:192.168.1.21' http://example.id
curl --resolve 'example.id:80:<Ingress_Controller_externalIPs>' http://example.id