{"id":50574,"date":"2025-07-22T10:42:11","date_gmt":"2025-07-22T10:42:11","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=50574"},"modified":"2025-07-23T04:36:23","modified_gmt":"2025-07-23T04:36:23","slug":"kubernetes-how-to-run-a-pod-and-get-the-egress-ip-address-kuberneteseks","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/kubernetes-how-to-run-a-pod-and-get-the-egress-ip-address-kuberneteseks\/","title":{"rendered":"Kubernetes: How to Run a Pod and Get the EGRESS IP Address KubernetesEKS"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-deploy-a-pod-to-your-cluster\">1. Deploy a Pod to Your Cluster<\/h2>\n\n\n\n<p>You can launch a simple Pod using the <code>kubectl run<\/code> command. For example, to run an NGINX Pod:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<code>kubectl run my-nginx --image=nginx --restart=Never\n<\/code><\/pre>\n\n\n\n<p>Wait until the pod is in the <code>Running<\/code> state:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<code>kubectl get pod my-nginx -o wide\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-get-pod-egress-ip-address\">2. Get Pod EGRESS IP Address<\/h2>\n\n\n\n<p>To determine the IP address seen by external services (egress\/source IP), execute the following steps:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step A: Get a Shell Inside the Pod<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>kubectl exec -it my-nginx -- \/bin\/sh<br><\/code><\/pre>\n\n\n\n<p><em>(If <code>\/bin\/sh<\/code> is not present, replace with <code>\/bin\/bash<\/code> or use another pod\/container image that has a shell.)<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step B: Query an External Service for the Pod&#8217;s Egress IP<\/h2>\n\n\n\n<p>Within the pod shell, run:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>curl https:\/\/ifconfig.me<br><\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">text<code>curl https:\/\/api.ipify.org\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The response will be the <strong>egress\/public IP<\/strong> as seen by the Internet.<\/li>\n\n\n\n<li>This will usually be:\n<ul class=\"wp-block-list\">\n<li>The EC2 node&#8217;s public IP address <strong>if your nodes are in a public subnet<\/strong>, or<\/li>\n\n\n\n<li>The NAT Gateway&#8217;s Elastic IP <strong>if your worker nodes are in private subnets<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>If <code>curl<\/code> is not installed in the container, you can:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use an image that includes <code>curl<\/code> (e.g., <code>ubuntu<\/code>, <code>alpine<\/code>)<\/li>\n\n\n\n<li>Install it on-the-fly, e.g., <code>apk add curl<\/code> in Alpine Linux or <code>apt-get update &amp;&amp; apt-get install curl -y<\/code> in Ubuntu.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-example-pod-command\">3. Example Pod Command<\/h2>\n\n\n\n<p>If you want to create a one-off pod with <code>curl<\/code> available:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<code>kubectl run tmp-curl-pod --rm -it --image=alpine --restart=Never -- sh\n<em># Inside the shell, run:<\/em>\napk add curl\ncurl https:\/\/ifconfig.me\nexit\n<\/code><\/pre>\n\n\n\n<p>When you exit, the pod will be cleaned up automatically.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-quick-table-what-each-ip-means\">4. Quick Table: What Each IP Means<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Step<\/th><th>Command<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>Pod internal IP<\/td><td><code>kubectl get pod my-nginx -o wide<\/code><\/td><td>Cluster-local Pod IP<\/td><\/tr><tr><td>Egress\/public IP<\/td><td><code>curl https:\/\/ifconfig.me<\/code> in pod<\/td><td>Internet-facing source IP<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-what-determines-egress-ip-in-aws-eks\">5. What Determines Egress IP in AWS EKS?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For standard AWS EKS setups:\n<ul class=\"wp-block-list\">\n<li><strong>Public Node:<\/strong> Outbound IP is usually the node\u2019s public IP.<\/li>\n\n\n\n<li><strong>Private Node:<\/strong> Outbound IP is the NAT Gateway\u2019s Elastic IP.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>If using advanced networking (like Calico with Egress IP pools or Egress Gateway), the IP could be different, but in default setups, the above holds.<\/li>\n<\/ul>\n\n\n\n<p><strong>Summary:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Deploy pod.<\/li>\n\n\n\n<li>Open a shell inside.<\/li>\n\n\n\n<li>Use <code>curl<\/code> to an external service to print the egress\/public IP.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Deploy a Pod to Your Cluster You can launch a simple Pod using the kubectl run command. For example, to run an NGINX Pod: bashkubectl run my-nginx &#8211;image=nginx &#8211;restart=Never&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-50574","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=50574"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50574\/revisions"}],"predecessor-version":[{"id":50581,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50574\/revisions\/50581"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=50574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=50574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=50574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}