Kubernetes cov lus qhia & kev ua kom yuam kev: nplooj ntawv yuam kev hauv NGINX Ingress
Hauv tsab xov xwm no, kuv xav tham txog ob yam ntawm NGINX Ingress ntsig txog kev nthuav tawm cov nplooj ntawv yuam kev ntawm tus kheej, nrog rau cov kev txwv uas muaj nyob hauv lawv thiab txoj hauv kev ua haujlwm nyob ib puag ncig lawv.
1. Hloov lub neej ntawd backend
Los ntawm lub neej ntawd, NGINX Ingress siv lub neej ntawd backend, uas ua haujlwm sib xws. Qhov no txhais tau hais tias thaum thov Ingress qhia tus tswv tsev uas tsis nyob hauv Ingress cov peev txheej, peb tau txais nplooj ntawv hauv qab no nrog 404 cov lus teb:
Txawm li cas los xij, ntau thiab ntau zaus peb cov neeg siv khoom tuaj nrog kev thov kom qhia lawv cov nplooj ntawv nrog lub tuam txhab logo thiab lwm yam khoom siv tsis yog tus qauv 404. Txhawm rau ua qhov no, NGINX Ingress muaj built-in muaj peev xwm rov txhais dua default-backend-service. Peb dhau lub hom ntawv nkag raws li kev sib cav rau qhov kev xaiv ntawm tib lub npe namespace/servicename. Qhov chaw nres nkoj yuav tsum yog 80.
Txhawm rau ua qhov no, koj yuav tsum tsim koj tus kheej pod (kev xa tawm) thiab kev pabcuam nrog koj daim ntawv thov (piv txwv kev siv hauv YAML los ntawm ingress-nginx repository), uas yuav muab es tsis txhob ntawm lub neej ntawd backend.
Nov yog ib daim duab me me:
~$ curl -i -XGET http://sadsdasdas.kube-cloud.my/
HTTP/1.1 404 Not Found
Date: Mon, 11 Mar 2019 05:38:15 GMT
Content-Type: */*
Transfer-Encoding: chunked
Connection: keep-alive
<span>The page you're looking for could not be found.</span>
Yog li tag nrho cov npe uas tsis yog tsim los ntawm YAML nrog kind: Ingress, poob rau hauv default-backend. Nyob rau hauv cov npe saum toj no, qhov no tau los ua sadsdasdas.
2. Tuav HTTP yuam kev hauv daim ntawv thov siv lub neej ntawd backend
Lwm qhov xwm txheej yog thov xaus rau HTTP yuam kev (404, 500, 502 ...) rau ib daim ntawv thov uas tsis ua cov xwm txheej zoo li no (cov nplooj ntawv zoo nkauj tsis raug tsim tawm). Qhov no kuj yog vim qhov kev xav ntawm cov neeg tsim khoom los ua haujlwm rau tib nplooj ntawv yuam kev hauv ntau daim ntawv thov.
Txhawm rau siv cov ntaub ntawv no ntawm server sab peb xav tau:
Ua raws li cov lus qhia saum toj no los ntawm kab lus hais txog lub neej ntawd backend;
Ntxiv tus yuam sij rau nginx-ingress configuration ConfigMap custom-http-errors, piv txwv li, nrog tus nqi 404,503 (pom tseeb sib raug rau cov lej yuam kev uas tau them los ntawm txoj cai tshiab).
Qhov kev xav tau tau ua tiav: thaum daim ntawv thov tus neeg siv tau khiav thiab tau txais qhov yuam kev nrog cov lus teb 404 lossis 503, qhov kev thov yuav raug xa rov qab mus rau qhov rov qab ua haujlwm tshiab ...
Txawm li cas los xij, thaum tsim ib daim ntawv thov rau lub neej ntawd backend thiab kev cai-http-yuam kev, koj yuav tsum coj mus rau hauv tus account ib qho tseem ceeb feature:
!!! Important The custom backend is expected to return the correct HTTP status code instead of 200. NGINX does not change the response from the custom default backend.
Hauv qhov no, qhov yuam kev 404 thiab 502 yuav raug xa rov qab mus rau cov nplooj ntawv yuam kev nrog txhua qhov tsim nyog headers.
В yav dhau los versions ntawm Ingress tsis muaj qhov tshwj xeeb no (txoj hmoo phem 0.23). Thiab yog tias koj muaj 2 daim ntawv thov sib txawv kiag li khiav hauv koj pawg thiab koj xav qhia kom meej qhov sib txawv ntawm lub neej ntawd-backend-kev pabcuam thiab kev ua haujlwm ntawm cov lej sib txawv rau lawv txhua tus, rau qhov no koj yuav tau siv kev ua haujlwm, uas peb muaj ob.
Ingress <0.23: mus rau ib qho
Qhov kev xaiv no yooj yim dua. Raws li ib daim ntawv thov uas ua haujlwm rau nws cov nplooj ntawv, peb muaj HTML li niaj zaus, uas tsis paub yuav ua li cas saib cov headers thiab xa cov lus teb kom raug. Xws li ib daim ntawv thov yog dov tawm nrog Ingress los ntawm url /error-pages, thiab hauv catalog ws yuav yog HTML rov qab.