Headless 的作用

轉(zhuǎn)載自Marco Luksa
Each connection to the service is forwarded to one randomly selected backing pod. But what if the client needs to connect to all of those pods? What if the backing pods themselves need to each connect to all the other backing pods. Connecting through the service clearly isn’t the way to do this. What is?

For a client to connect to all pods, it needs to figure out the the IP of each individual pod. One option is to have the client call the Kubernetes API server and get the list of pods and their IP addresses through an API call, but because you should always strive to keep your apps Kubernetes-agnostic, using the API server isn’t ideal

Luckily, Kubernetes allows clients to discover pod IPs through DNS lookups. Usually, when you perform a DNS lookup for a service, the DNS server returns a single IP — the service’s cluster IP. But if you tell Kubernetes you don’t need a cluster IP for your service (you do this by setting the clusterIP field to None in the service specification ), the DNS server will return the pod IPs instead of the single service IP. Instead of returning a single DNS A record, the DNS server will return multiple A records for the service, each pointing to the IP of an individual pod backing the service at that moment. Clients can therefore do a simple DNS A record lookup and get the IPs of all the pods that are part of the service. The client can then use that information to connect to one, many, or all of them.

Setting the clusterIP field in a service spec to None makes the service headless, as Kubernetes won’t assign it a cluster IP through which clients could connect to the pods backing it.

如果某個應(yīng)用想訪問所有的后端節(jié)點(diǎn),可以使用Headless Service,不配置cluster IP

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末蓄拣,一起剝皮案震驚了整個濱河市茫因,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌鸦难,老刑警劉巖珍语,帶你破解...
    沈念sama閱讀 221,406評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件强衡,死亡現(xiàn)場離奇詭異形葬,居然都是意外死亡合呐,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,395評論 3 398
  • 文/潘曉璐 我一進(jìn)店門笙以,熙熙樓的掌柜王于貴愁眉苦臉地迎上來淌实,“玉大人,你說我怎么就攤上這事猖腕〔鹌恚” “怎么了?”我有些...
    開封第一講書人閱讀 167,815評論 0 360
  • 文/不壞的土叔 我叫張陵倘感,是天一觀的道長放坏。 經(jīng)常有香客問我,道長老玛,這世上最難降的妖魔是什么淤年? 我笑而不...
    開封第一講書人閱讀 59,537評論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮蜡豹,結(jié)果婚禮上麸粮,老公的妹妹穿的比我還像新娘。我一直安慰自己镜廉,他們只是感情好弄诲,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,536評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著娇唯,像睡著了一般齐遵。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上塔插,一...
    開封第一講書人閱讀 52,184評論 1 308
  • 那天梗摇,我揣著相機(jī)與錄音,去河邊找鬼佑淀。 笑死留美,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的伸刃。 我是一名探鬼主播谎砾,決...
    沈念sama閱讀 40,776評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼捧颅!你這毒婦竟也來了景图?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,668評論 0 276
  • 序言:老撾萬榮一對情侶失蹤碉哑,失蹤者是張志新(化名)和其女友劉穎挚币,沒想到半個月后亮蒋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,212評論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡妆毕,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,299評論 3 340
  • 正文 我和宋清朗相戀三年慎玖,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片笛粘。...
    茶點(diǎn)故事閱讀 40,438評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡趁怔,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出薪前,到底是詐尸還是另有隱情润努,我是刑警寧澤,帶...
    沈念sama閱讀 36,128評論 5 349
  • 正文 年R本政府宣布示括,位于F島的核電站铺浇,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏垛膝。R本人自食惡果不足惜鳍侣,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,807評論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望繁涂。 院中可真熱鬧拱她,春花似錦、人聲如沸扔罪。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,279評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽矿酵。三九已至唬复,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間全肮,已是汗流浹背敞咧。 一陣腳步聲響...
    開封第一講書人閱讀 33,395評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留辜腺,地道東北人休建。 一個月前我還...
    沈念sama閱讀 48,827評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像评疗,于是被迫代替她去往敵國和親测砂。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,446評論 2 359

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