Ingress Nginx 試用

安裝ingress-nginx

[root@bogon:~/k8s/ingress/ingress-nginx# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml]
[namespace "ingress-nginx" created](interm)

[deployment "default-http-backend" created](interm)

[service "default-http-backend" created](interm)

[configmap "nginx-configuration" created](interm)

[configmap "tcp-services" created](interm)

[configmap "udp-services" created](interm)

[serviceaccount "nginx-ingress-serviceaccount" created](interm)

[clusterrole "nginx-ingress-clusterrole" created](interm)

[role "nginx-ingress-role" created](interm)

[rolebinding "nginx-ingress-role-nisa-binding" created](interm)

[clusterrolebinding "nginx-ingress-clusterrole-nisa-binding" created](interm)

[deployment "nginx-ingress-controller" created](interm)

[root@bogon:~/k8s/ingress/ingress-nginx# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml

安裝完成后,查看一下ingress-nginx相關(guān)的組件的創(chuàng)建情況:

root@bogon:~/k8s/ingress/ingress-nginx# kubectl get pods -n ingress-nginx 
NAME                                        READY     STATUS              RESTARTS   AGE
default-http-backend-55c6c69b88-rfq4n       0/1       ContainerCreating   0          29s
nginx-ingress-controller-7cc74ccd44-h827j   0/1       ContainerCreating   0          28s

從上圖中看出nginx-ingress-controller和default-http-backend兩個組件都正在創(chuàng)建氛什,間隔一段時間俗他,繼續(xù)觀察,知道Pod處于運(yùn)行狀態(tài)

root@bogon:~/k8s/ingress# kubectl get pods -n ingress-nginx 
NAME                                        READY     STATUS    RESTARTS   AGE
default-http-backend-55c6c69b88-rfq4n       1/1       Running   1          6d
nginx-ingress-controller-7cc74ccd44-h827j   1/1       Running   1          6d

到現(xiàn)在為止,說明整個ingress-nginx的組件已經(jīng)全部啟動瞬矩,查看相應(yīng)的組件:

root@bogon:~/k8s/ingress# kubectl get service -n ingress-nginx                    
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
default-http-backend   ClusterIP   10.111.66.202    <none>        80/TCP                       6d
ingress-nginx          NodePort    10.98.149.237    <none>        80:31230/TCP,443:30458/TCP   6d

驗(yàn)證服務(wù)安裝的服務(wù)的可用性,系統(tǒng)自動安裝了一個default-http-backend悔政,這是一個缺省的http后端服務(wù)翁涤,用于返回404結(jié)果桥言,如下所示:

default backend - 404root@bogon:~/k8s/ingress# kubectl get service ingress-nginx -n ingress-nginx   
NAME            TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx   NodePort   10.98.149.237   <none>        80:31230/TCP,443:30458/TCP   6d
root@bogon:~/k8s/ingress# curl http://10.98.149.237:80
default backend - 404root@bogon:~/k8s/ingress# 
root@bogon:~/k8s/ingress# 
root@bogon:~/k8s/ingress# curl http://127.0.0.1:31230
default backend - 404root@bogon:~/k8s/ingress# 
root@bogon:~/k8s/ingress# 

從上文中萌踱,可以看出ingress-nginx是一個NodePort Servide,它除了向集群內(nèi)部暴漏ClusterIP:Port為10.98.149.237:80 号阿,同時還會向集群外部在每個節(jié)點(diǎn)上暴漏31230端口并鸵。

創(chuàng)建一個應(yīng)用以及相應(yīng)服務(wù)

準(zhǔn)備好Pod和Service的配置文件 nginx.yaml

---

apiVersion: v1
kind: Pod
metadata:
 name: nginx
 namespace: ingress-nginx
 labels:
   app: web
spec:
 hostNetwork: false
 containers:
   - name: nginx
     image: nginx

---

kind: Service
apiVersion: v1
metadata:
  name: my-service
  namespace: ingress-nginx
spec:
  selector:
    app: web
  ports:
  - protocol: TCP
    port: 1005
    targetPort: 80

創(chuàng)建nginx pod以及my-service服務(wù):

kubectl apply -f nginx.yaml
root@bogon:~/k8s/ingress# kubectl get service my-service -n ingress-nginx
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
my-service   ClusterIP   10.111.173.60   <none>        1005/TCP   2m
nginx-ingress-controller-7cc74ccd44-h827j   1/1       Running   1          6d
root@bogon:~/k8s/ingress# kubectl get pod nginx -n ingress-nginx  
NAME      READY     STATUS    RESTARTS   AGE
nginx     1/1       Running   0          2m

驗(yàn)證服務(wù)是否可用:

root@bogon:~/k8s/ingress# curl http://10.111.173.60:1005
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

創(chuàng)建ingress服務(wù)

準(zhǔn)備好test-ingress.yaml文件

root@bogon:~/k8s/ingress# cat test-ingress.yaml 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
  namespace: ingress-nginx
spec:
  rules:
  -  host: foo.bar.com
     http:
      paths:
      - path: /
        backend:
          serviceName: my-service
          servicePort: 1005

驗(yàn)證ingress反向代理服務(wù):

root@bogon:~/k8s/ingress# curl http://127.0.0.1:31230 
default backend - 404root@bogon:~/k8s/ingress# 
root@bogon:~/k8s/ingress# 
root@bogon:~/k8s/ingress# 
root@bogon:~/k8s/ingress# curl -H "Host: foo.bar.com" http://127.0.0.1:31230/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市扔涧,隨后出現(xiàn)的幾起案子园担,更是在濱河造成了極大的恐慌,老刑警劉巖枯夜,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件弯汰,死亡現(xiàn)場離奇詭異,居然都是意外死亡湖雹,警方通過查閱死者的電腦和手機(jī)咏闪,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來劝枣,“玉大人汤踏,你說我怎么就攤上這事√蛱冢” “怎么了溪胶?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長稳诚。 經(jīng)常有香客問我哗脖,道長,這世上最難降的妖魔是什么扳还? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任才避,我火速辦了婚禮,結(jié)果婚禮上氨距,老公的妹妹穿的比我還像新娘桑逝。我一直安慰自己,他們只是感情好俏让,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布楞遏。 她就那樣靜靜地躺著,像睡著了一般首昔。 火紅的嫁衣襯著肌膚如雪寡喝。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天勒奇,我揣著相機(jī)與錄音预鬓,去河邊找鬼。 笑死赊颠,一個胖子當(dāng)著我的面吹牛格二,可吹牛的內(nèi)容都是我干的劈彪。 我是一名探鬼主播,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼蟋定,長吁一口氣:“原來是場噩夢啊……” “哼粉臊!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起驶兜,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤扼仲,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后抄淑,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體屠凶,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年肆资,在試婚紗的時候發(fā)現(xiàn)自己被綠了矗愧。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,795評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡郑原,死狀恐怖唉韭,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情犯犁,我是刑警寧澤属愤,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站酸役,受9級特大地震影響住诸,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜涣澡,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一贱呐、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧入桂,春花似錦奄薇、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至驹愚,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間劣纲,已是汗流浹背逢捺。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留癞季,地道東北人劫瞳。 一個月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓倘潜,卻偏偏與公主長得像,于是被迫代替她去往敵國和親志于。 傳聞我的和親對象是個殘疾皇子涮因,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,724評論 2 354

推薦閱讀更多精彩內(nèi)容