<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ChihChiangChen on Medium]]></title>
        <description><![CDATA[Stories by ChihChiangChen on Medium]]></description>
        <link>https://medium.com/@great_bole_wildebeest_372?source=rss-c643e99426ca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-Ny-YxxxlgjKjG5C</url>
            <title>Stories by ChihChiangChen on Medium</title>
            <link>https://medium.com/@great_bole_wildebeest_372?source=rss-c643e99426ca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:59:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@great_bole_wildebeest_372/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AWS 省錢方法 1]]></title>
            <link>https://medium.com/@great_bole_wildebeest_372/aws-%E7%9C%81%E9%8C%A2%E6%96%B9%E6%B3%95-1-1d368f55cb0b?source=rss-c643e99426ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d368f55cb0b</guid>
            <category><![CDATA[aws-cost-optimization]]></category>
            <dc:creator><![CDATA[ChihChiangChen]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 05:46:51 GMT</pubDate>
            <atom:updated>2023-03-19T05:46:51.519Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>盡量不要有 Cross AZ 的網路存取。</strong></p><p>Cross AZ 的費用是： $0.1/GB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wVHRiGZTDagzPRbA.png" /><figcaption><a href="https://user-images.githubusercontent.com/7160463/64160641-dbbf9100-ce6e-11e9-9663-7279916af3b9.png">https://user-images.githubusercontent.com/7160463/64160641-dbbf9100-ce6e-11e9-9663-7279916af3b9.png</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XWCUOlA98bf7SLSS.jpg" /><figcaption><a href="https://www.lastweekinaws.com/wp-content/uploads/2019/12/dbg010-datatxfr-infographic-20191219.jpg">https://www.lastweekinaws.com/wp-content/uploads/2019/12/dbg010-datatxfr-infographic-20191219.jpg</a></figcaption></figure><p>如果有像是 elasticsearch 這類的服務，會產生大量的資料同步行為，千萬不要 Cross AZ，不然會產生很多 Cross AZ 的費用。</p><p><strong>如果 log 資料總量如果 1.2TB，存在三台節點(AZ)上，流量費會是 800GB，約等於 $80。所以 elasticsearch 的節點都要放在同一個 AZ，以免產生高額的 Cross AZ 費用。</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d368f55cb0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何讓 Keep-Alive Connection 在 Kubernetes 上達到負載均衡？(續)]]></title>
            <link>https://medium.com/@great_bole_wildebeest_372/%E5%A6%82%E4%BD%95%E8%AE%93-keep-alive-connection-%E5%9C%A8-kubernetes-%E4%B8%8A%E9%81%94%E5%88%B0%E8%B2%A0%E8%BC%89%E5%9D%87%E8%A1%A1-%E7%BA%8C-a91f6165594e?source=rss-c643e99426ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/a91f6165594e</guid>
            <dc:creator><![CDATA[ChihChiangChen]]></dc:creator>
            <pubDate>Thu, 26 Mar 2020 09:08:00 GMT</pubDate>
            <atom:updated>2020-03-26T09:08:00.593Z</atom:updated>
            <content:encoded><![CDATA[<p>單以 Kubernetes Service 的原生功能是無法達到此目標，但維運人員的實力就是能不能透過一系列工具的組合來達成目標。</p><p>當連線增加時，可以使用以下作法</p><ol><li>將同樣的服務建成三個 Deployment (原本是一個)，設定 DNS weight 為100:0:0 ，所有的連線都只會導向 Deployment 1。</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D0sd189Xc7s9ILHJ.png" /></figure><p>2. 當 Deployment 1 的負載過高時，增加 Deployment 2 的 Pod 個數，並將 DNS weight 調整為 20:80:0。這樣比較多的<strong>新連線</strong>就會導向 Deployment 2。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vbrIKYrZXDniQoS_.png" /></figure><p>3. 當 Deployment 1,2 的負載過高時，增加 Deployment 3的 Pod 個數，並將 DNS weight 調整為 10:10:80。這樣比較多的<strong>新連線</strong>就會導向 Deployment 3。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BjIMq1cWRiZC2l3B.png" /></figure><p>當連線減少時，可以使用以下作法</p><ol><li>把 DNS weight 設定為 50:50:0，讓新連線不要再連到 Deployment 3。等到 Deployment 3 沒有連線後，再把 Replica 設定為 0。</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GyLBO7zu-qa4nadB.png" /></figure><p>2. 再把 DNS weight 設定為 100:0:0，讓新連線不要再連到 Deployment 2。等到 Deployment 2沒有連線後，再把 Replica 設定為 0。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9fJ3cKpL-L9fyyMo.png" /></figure><p>總結：<br>以上方法以幾點好處：</p><ol><li>透過 DNS Weight 可以手動調整 <strong>新連線 </strong>連到每個一 Deployment 的機率。<br>如果只使用一個 Deployment ，增加 Replica 只會增加 Pod 的數量，新舊 Pod 收到新連線的機率還是一樣的。這在 Keep-Ailve 的應用下，會讓新舊 Pod 的負載極不平均。</li><li>連線數變少，要刪除一些 Pod 時，如果直接降低 Replica 數量，Deployment 會自己挑選那些 Pod 要被刪除，這時有可能會讓某些 Client 斷線。透過多個 Deployment 和 DNS Weight 功能，可以讓連線慢慢集中到一個 Deployment 上，空閒下來的 Deployment 就可以將 Pod 完全刪除。</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a91f6165594e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何讓 keep-alive Connection 在 Kubernetes 上達到負載均衡？]]></title>
            <link>https://medium.com/@great_bole_wildebeest_372/%E5%A6%82%E4%BD%95%E8%AE%93-keep-alive-connection-%E5%9C%A8-kubernetes-%E4%B8%8A%E9%81%94%E5%88%B0%E8%B2%A0%E8%BC%89%E5%9D%87%E8%A1%A1-c5929368ba16?source=rss-c643e99426ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5929368ba16</guid>
            <dc:creator><![CDATA[ChihChiangChen]]></dc:creator>
            <pubDate>Wed, 25 Mar 2020 10:15:08 GMT</pubDate>
            <atom:updated>2020-03-25T10:16:19.059Z</atom:updated>
            <content:encoded><![CDATA[<h3>如何讓 Keep-Alive Connection 在 Kubernetes 上達到負載均衡？</h3><p>最近有朋友問到 Kubernetes Service 的 Round-Robin 在某些狀況下無法將流量平均的發送到後端的 Pod。</p><p>就我的經驗，有幾種狀況可能會這樣。</p><ol><li>Client 會對 Server 建立 Connection Pool。</li><li>應用的類型是長連結。</li></ol><p>第一種狀況好解決，以往為了減少每次建立連線時所消耗的資源，都會建立 Connection Pool。只要取消這樣的機制或是定期重解析的 IP 即可。</p><p>第二種狀況就比較複雜了，一般都是在原有的 Pod 負載已經過高了才會增加 Pod，此時原有的 Pod 已經有不少的長連結連線了，新的連線還是會依照 Round-Robin 去分配到所有的 Pod (包括原有的Pod)，所以無法達到最終的<strong>負載平衡</strong>。</p><p>可以參考以下文章：<br><a href="https://learnk8s.io/kubernetes-long-lived-connections?fbclid=IwAR1GAX1EZwPV5FcMzXbqZMCZeguHTUF_t21Q04W_POS8iZWXnUC_s9Bvn-k">Load balancing and scaling long-lived connections in Kubernetes</a></p><p>以三個 Pod 為例，它的 Round-Robin 會這樣設定</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*mW5z4W2xIKDc_FaayZvoFw.png" /><figcaption><a href="https://learnk8s.io/a/a9a79c07ae5c96d0ddcaa82d43c66622.svg">https://learnk8s.io/a/a9a79c07ae5c96d0ddcaa82d43c66622.svg</a></figcaption></figure><p>它不會管現在有多少個連線已經建立，而是讓新的連線平均的分配在每一個 Pod 上面。</p><p>如果這個應用是長連結類型，維運人員希望的是讓新增加的 Pod 多接一點連線，而舊有的 Pod 少接一點連線，進而達成負載平衡。很可惜，以 Kuberbetes 原生的功能無法達成這樣的目標。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5929368ba16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS EKS 使用 ALB + IP mode 來減少 Inter-AZ 的流量費 (補充)]]></title>
            <link>https://medium.com/@great_bole_wildebeest_372/aws-eks-%E4%BD%BF%E7%94%A8-alb-ip-mode-%E4%BE%86%E6%B8%9B%E5%B0%91-inter-az-%E7%9A%84%E6%B5%81%E9%87%8F%E8%B2%BB-%E8%A3%9C%E5%85%85-e38037406a77?source=rss-c643e99426ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/e38037406a77</guid>
            <dc:creator><![CDATA[ChihChiangChen]]></dc:creator>
            <pubDate>Thu, 12 Mar 2020 08:05:24 GMT</pubDate>
            <atom:updated>2020-03-12T14:49:00.410Z</atom:updated>
            <content:encoded><![CDATA[<p>本篇是補充前兩篇沒提到的細節：<br>(謎之音：不懂也沒關係…)</p><p>1 .Pod 在被刪除前，不是應該會有一段時間讓連線 Drain 掉嗎(terminationGracePeriodSeconds)？會何還是會有 502/503 出現？</p><p>2. 為何使用 CLB 不會有這樣的問題？</p><p>先看<a href="https://kubernetes.io/zh/docs/concepts/workloads/pods/pod/#pod-%E7%9A%84%E7%BB%88%E6%AD%A2">官方網站</a>和<a href="https://dzone.com/articles/kubernetes-lifecycle-of-a-pod">一篇 dzone 的文章</a>對於 Pod的終止的各步驟的詳細解說：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsw-vSPeBR5eFHHgF2Lnrw.png" /><figcaption><a href="https://kubernetes.io/zh/docs/concepts/workloads/pods/pod/#pod-%E7%9A%84%E7%BB%88%E6%AD%A2">https://kubernetes.io/zh/docs/concepts/workloads/pods/pod/#pod-%E7%9A%84%E7%BB%88%E6%AD%A2</a></figcaption></figure><h3>Termination of a Pod</h3><figure><img alt="https://dzone.com/articles/kubernetes-lifecycle-of-a-pod" src="https://cdn-images-1.medium.com/max/1020/0*31XSV8V5SciEffdZ.jpg" /><figcaption><a href="https://dzone.com/articles/kubernetes-lifecycle-of-a-pod">https://dzone.com/articles/kubernetes-lifecycle-of-a-pod</a></figcaption></figure><p>文件上提到，當 Pod 要被刪除時：<br>1. 會設定 terminationGracePeriodSeconds 為 30 秒(此為預設值，可更改)。<br>2. 把 Pod 從 Endpoint 中移除，這樣就不會有流量導過去。<br>3–1. 執行 preStop 指令(如果有設定的話)。<br>3–2. 送出 TERM Signal，讓程序把現有的連線處理完就自行關閉。<br>4. 等 30 秒(如果 preStop 還沒跑完，會再多等 2 秒)沒有自己關閉程序，就會送出 SIGKILL，讓它強制關閉。</p><p>使用 ALB 會出現 502/503 的狀況為：<br>當 Pod 被標記為 Termination 時，把它從 Endpoint 中移除，沒有 preStop 指令，<strong>對 Pod 送出 TERM Signal 後，程序就關閉了。此時 ALB Ingress Controller 還來不及知道這件事。</strong></p><p>因為 ALB ingress controller 是定期去問 EKS Master 來取得資訊並更新 Target Group，所以會有一小段的時間差。當連線連到 ALB 時，會被導到後面的 Target Group，還是會送到已經不存在的 Pod，所以就有 502/503。</p><p>用了 preStop 可以讓 Pod 關閉的慢一點，讓 ALB Ingress Controller 來的及問 EKS Master 並更新 Target Group，刪除已經不存在的 Pod，也就不會回應 502/503 。</p><p>那為何使用 CLB 不會有問題呢？<br>當 Pod 被標記為 Termination 時，把它從 Endpoint 中移除，沒有 preStop 指令，對 Pod 送出 TERM Signal 後，程序就關閉了。( 這邊都一樣…)</p><p>而 CLB 的後端是每一台的 Worker node，它只把連線送給 Worker node，接下來就 Endpoint 去找到 Pod 的 IP 並往它送(這一段跟 CLB 無關)。<strong>Endpoint 在 Pod 被標記為 Termination 的同一時間已經被更新了</strong>，所以不會送到不存在的 Pod，也就不會 502/503 。</p><p>以上是我對於此現象的理解，也不代表一定是 100% 正確，供大家參考囉。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e38037406a77" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS EKS 使用 ALB + IP mode 來減少 Inter-AZ 的流量費 (續)]]></title>
            <link>https://medium.com/@great_bole_wildebeest_372/aws-eks-%E4%BD%BF%E7%94%A8-alb-ip-mode-%E4%BE%86%E6%B8%9B%E5%B0%91-inter-az-%E7%9A%84%E6%B5%81%E9%87%8F%E8%B2%BB-%E7%BA%8C-d373225d8522?source=rss-c643e99426ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/d373225d8522</guid>
            <dc:creator><![CDATA[ChihChiangChen]]></dc:creator>
            <pubDate>Tue, 10 Mar 2020 09:35:35 GMT</pubDate>
            <atom:updated>2020-03-10T14:13:38.921Z</atom:updated>
            <content:encoded><![CDATA[<p>在上一篇的結尾有提到，如果那麼好，為何大家不用呢？是不是有什麼坑在裡面呢？</p><p>答案是：<strong>有</strong></p><p>會遇到的問題是在 Rolling Update 時，會讓 Client 某些連線得到 502/503 的回應值。簡單的說，就是可能會讓使用者查覺到 ”連線有問題” 或 “會觸發告警”。</p><p>請參考：<a href="https://github.com/kubernetes-sigs/aws-alb-ingress-controller/issues/814#issuecomment-454593300">https://github.com/kubernetes-sigs/aws-alb-ingress-controller/issues/814#issuecomment-454593300</a></p><p>在實驗中也確實會發生這樣的情況。<br>我們的實驗方式是用建立一個 4 個 Pod 的 Nginx Deployment ，<br>使用 <a href="https://github.com/JoeDog/siege">siege</a> 一直去對它存取，並同時對 Deployment 進行 Rolling Update，<br>結果是不盡理想，Availability 只有 96.69%。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*IjGLJu1GFGWB1kGP.png" /></figure><pre>siege -c 100 -r 100 -d1 &quot;http://xxxxxxx.us-east-x.elb.amazonaws.com&quot;</pre><pre>Transactions:               9669 hits<br><strong>Availability:               96.69 %</strong><br>Elapsed time:               81.45 secs<br>Data transferred:           5.69 MB<br>Response time:              0.15 secs<br>Transaction rate:           118.71 trans/sec<br>Throughput:                 0.07 MB/sec<br>Concurrency:                18.16<br>Successful transactions:    9669<br>Failed transactions:        331<br>Longest transaction:        10.01<br>Shortest transaction:       0.00</pre><p>那麼接下來我們能做有兩個方向<br>1. 從程式面下手，例如 改 source code，或開 Case 給 AWS 請他們改 ALB 的機制。<br>2. 從應用面下手，利用 Kubernetes 原有的功能來達到平穩的 Rolling Update。</p><p>我們是往應用面研究和實驗。</p><p>如果能讓 Pod 在被刪除時多活久一點，讓 ALB 發現它已經要被刪除，它就會變成 Drian 的狀態，就不會有連線再連到它，也不會產生 502/503 的回應值了。</p><p>Kubernetes 的 Deployment 中有一個功能是 Lifecycle，可設定 postStart 和 preStop。一個是在 Pod <strong>運行後要先執行</strong>什麼指令和<strong>刪除前先要執行</strong>什麼指令。</p><p>請參考：<a href="https://kubernetes.io/zh/docs/tasks/configure-pod-container/attach-handler-lifecycle-event">https://kubernetes.io/zh/docs/tasks/configure-pod-container/attach-handler-lifecycle-event</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vktdszQNG6KGTAx3.png" /></figure><p>在 Nginx Deployment 中加入這一段，再進行 Rolling Update，就不會得到 502/503 的回應值了。</p><pre>lifecycle:<br>  preStop:<br>    exec:<br>      command:<br>      - sleep<br>      - &quot;30&quot;</pre><p>這樣它被刪除時，會等待 30 秒，足以讓 ALB 發現它的狀態已經改變，而會被標記為 Drain 狀態。以下是新的測試結果，Availability 是 100%，非常理想。</p><pre>siege -c 100 -r 100 -d1 &quot;http://xxxxxxx.us-east-x.elb.amazonaws.com&quot;</pre><pre>Transactions:               10000 hits<br><strong>Availability:               100.00 %</strong><br>Elapsed time:               62.41 secs<br>Data transferred:           5.84 MB<br>Response time:              0.00 secs<br>Transaction rate:           160.23 trans/sec<br>Throughput:                 0.09 MB/sec<br>Concurrency:                0.68<br>Successful transactions:    10000<br>Failed transactions:        0<br>Longest transaction:        0.09<br>Shortest transaction:       0.00</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d373225d8522" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS EKS 使用 ALB + IP mode 來如節省 Inter-AZ 的流量費]]></title>
            <link>https://medium.com/@great_bole_wildebeest_372/aws-eks-%E4%BD%BF%E7%94%A8-alb-ip-mode-%E4%BE%86%E5%A6%82%E7%AF%80%E7%9C%81-inter-az-%E7%9A%84%E6%B5%81%E9%87%8F%E8%B2%BB-6cde7de5154a?source=rss-c643e99426ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cde7de5154a</guid>
            <dc:creator><![CDATA[ChihChiangChen]]></dc:creator>
            <pubDate>Sun, 08 Mar 2020 08:59:15 GMT</pubDate>
            <atom:updated>2020-03-09T15:13:03.992Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS EKS 使用 ALB + IP mode 來減少 Inter-AZ 的流量費</h3><p>我們用了 kubernetes 已經有一年以上的時間，(<a href="https://github.com/kubernetes/kops">KOPS</a> 半年多，<a href="https://aws.amazon.com/tw/eks/">EKS</a> 半年多)<br>效果蠻好的，可以撐的住我們的業務量，新的服務都會是直接在 kubernetes 上運行。</p><p>使用 kubernetes 原生的逐步更新機制，讓我們軟體上版的的操作方便許多，可省下上版的所需要花費的時間，並透過多次小量更新來完成快速交付的目標。</p><p>但我想有在使用 AWS 的朋友們，都想或多或少的省一點 Inter-AZ 的費用，由其是使用了 kubernetes 後，這方面的費用會有明顯的增長。</p><p>原因是 kubernetes 的設計理念就是要 “流量分散” ，因為透過 “流量分散”，才不會有 ”單點失誤” 或 ”單點瓶頸” 的問題。當擴大運算力規模時，也可以享受到整體性能提升的好處。</p><p>Kubernetes 預設是至少使用三個 AZ (Availability Zone)，然後流量就會在三個 AZ 之間盡可能的達成均衡 (前提是 Pod 也要均衡的分佈在三個 AZ 之間)。</p><p>但每個月看著成長的 Inter-AZ 費用，就會想著如果能省一點有多好，畢竟老闆的角度來想，如果能幫公司省下可節省的費用，也是對公司收益有幫助（非營利部門不能賺錢，只能幫公司省錢…）。</p><p>如果要省錢，那就要了解 AWS 是如何計算 Inter-AZ 的費用，才能調整架構來達到降低費用的目標。</p><p>架構說明：<br>kubernetes 使用三個 AZ，在每一個 AZ 各有一台 EC2，每一個 EC2 裡面有兩個 pod，並透過 Load balancer (預設是 Classic Load Balancer) 來對外提供服務。如下圖所示</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1FdJiziDAbjGkg-lgDVGhA.png" /></figure><p>補充說明：<br>AWS Load Balancer 分三種， Application Load Balancer (ALB), Network Load Balancer (NLB)和 Classic，Load Balancer (CLB)，我們比較常用的是 CLB(預設) 和 ALB。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vBXoTaINtnsDUpqGaJ3LXA.png" /></figure><p>一般而言，在使用 CLB 時，當外部連線連到 kubernetes 時，會有以下三種狀況：</p><p>使用 CLB ，沒有 Inter-AZ ：<br>Client 從 DNS 上查到 CLB 三筆 A record，(隨機)連到任一個 IP，連到<strong>同 </strong>AZ 的 EC2 的 ENI(Elastic Network Interfaces)，透過 kube-proxy 連到<strong>同</strong> AZ 的 pod 的所在位置。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rrDF3kjhhN5IoXisGZMByA.png" /></figure><p>使用 CLB ，一次 Inter-AZ ：<br>Client 從 DNS 上查到 CLB 三筆 A record，(隨機)連到任一個 IP，連到<strong>不同 </strong>AZ 的 EC2 的 ENI，透過 kube-proxy 連到<strong>同</strong> AZ 的 pod 的所在位置。紅色線為 Inter-AZ。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Eb-EOxkREHqINe2UIMz0A.png" /></figure><p>使用 CLB ，兩次 Inter-AZ ：<br>Client 從 DNS 上查到 CLB 三筆 A record，(隨機)連到任一個 IP，連到<strong>不同 </strong>AZ 的 EC2 的 ENI，透過 kube-proxy 連到<strong>不同</strong> AZ 的 pod 的所在位置。紅色線為 Inter-AZ。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkNWzP41e0asN8qpM2nyiQ.png" /></figure><p>3*3*6 = 54 (總共有五十四種連線的組合)<br>3*1*2 = 6 (沒有 Inter-AZ 的次數)，6/54 = 11 (佔 11%)<br>3*1*2*2 (ELB 到 ENI 是 Inter-AZ) + 3*1*2*2 (ENI到EC2是 Inter-AZ)= 24 (一次 Inter-AZ 的次數)，24/54 = 44 (佔 44%)<br>3*2*4 (ELB 到 ENI 到 EC2 都是 Inter-AZ) = 24 (兩次 Inter-AZ 的次數)，24/54 = 44 (佔 44%)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXf87rpNiq00BbyGdeU8qw.png" /></figure><p>依據上圖的費用資訊，得知 ELB 傳到不同 AZ 的 EC2 是不收費的。<br>則剛剛得到的結果要更改為<br>3*1*2 = 6 (沒有 Inter-AZ 的次數)，6/54 = 11 (佔 11%)<br>3*1*2*2 = 12 (ELB到ENI是 Inter-AZ，不收費)，12/54 = 22 (佔 22%)<br>3*1*2*2 (ENI到EC2是 Inter-AZ)= 12 (一次 Inter-AZ 的次數)，12/54 = 22% (佔 22%)<br>3*2*4 (ELB到ENI到EC2都是 Inter-AZ，但ELB到ENI是 Inter-AZ，不收費) = 24 (兩次 Inter-AZ 的次數)，24/54 = 44% (佔 44%)</p><p>每 1000GB 的流量，則費用為<br>1000 * 11% ( 沒有 Inter-AZ ) * 0 (費用) ＝ 0<br>1000 * 22% ( ELB 到 ENI 是 Inter-AZ，不收費) * 0 (費用) ＝ 0<br>1000 * 22% ( ENI 到 EC2 是 Inter-AZ) * 0.01(費用) ＝ 4.4<br>1000 * 44% ( ELB 到 ENI 到 EC2 都是 Inter-AZ) * 0.02 (費用) = 8.8 ，8.8 / 2 = 4.4 (一次 Inter-AZ 不收費)<br>總費用為 0+0+4.4+4.4 = 8.8</p><p>如果改使用 ALB + IP mode，ALB 會直接把流量送到 pod，這樣就可以省掉一次 Inter-AZ 的機會。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hM8S92dpRVrw_YkjiywDw.png" /></figure><p>補充說明：<br>ALB 可以只選用兩個 AZ 建 Endpoint，CLB 則會在 EKS 所用到的 AZ 上都會建 Endpoint。</p><p>在使用 ALB + IP mode 時，當外部連線連到 kubernetes 時，會有以下幾兩狀況：</p><ol><li>沒有 Inter-AZ</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s3m31OoYzNWw2LyVGlTe4w.png" /></figure><p>2. 一次 Inter-AZ (ELB到ENI是 Inter-AZ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PI1pYij_cjowZJmojsKCBA.png" /></figure><p>依照剛剛的計費方式，ELB 到 ENI 是 Inter-AZ，是不收費。<br>如此一來就完全沒有 Inter-AZ 的費用了。</p><p>謎之音：如果那麼好，為何大家不用呢？是不是有什麼坑在裡面呢？</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cde7de5154a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>