You are signed in. Close

You are signed out. Close

Thank you. Your subscription has started. Close

Thank you. You will get an email when a new comic comes out. Close

We could not confirm your payment. If you paid, use the link "Sign in" at the bottom of the page. Close

Something went wrong on our side. Please try again in a moment. Close

Previous episode Pod IP addresses: why a replaced Kubernetes pod comes back with a new one

What happens when a visitor opens your app on Kubernetes

Kubernetes Service: one address that stays while pods come and go

In Kubernetes, pods are replaced all the time. Other apps still have to find them. They need one name and one address that never change, even when the pods behind them do.

  1. 1 Pods come and go, and their addresses go with them. Yet one thing on all your pods never changes.What do allyour pods havein common?app:cafe-menuapp:cafe-menuapp:cafe-menu

    Pods come and go, and their addresses go with them. Yet one thing on all your pods never changes.

  2. 2 Each one carries the sticker "app: cafe-menu". You wrote it in your app's file, and Kubernetes puts it on every pod it starts from that file. This sticker is called a label.app:cafe-menulabel

    Each one carries the sticker "app: cafe-menu". You wrote it in your app's file, and Kubernetes puts it on every pod it starts from that file. This sticker is called a label.

  3. 3 So you ask Kubernetes for a Service: one name and one address that stand for every pod with that label. Both stay as long as the Service exists.Service: cafe-menu10.96.0.20app:cafe-menuapp:cafe-menuapp:cafe-menu

    So you ask Kubernetes for a Service: one name and one address that stand for every pod with that label. Both stay as long as the Service exists.

  4. 4 The order app writes the Service's address on its note. Its requests go there, and the menu comes back from one of your pods.cafe-menu:10.96.0.20order appTo: 10.96.0.20Here'sthe menu!

    The order app writes the Service's address on its note. Its requests go there, and the menu comes back from one of your pods.

  5. 5 When a pod is replaced, the new one carries the label too, and the Service stands for it. The note stays right.Service: cafe-menu10.96.0.20app:cafe-menuapp:cafe-menuapp:cafe-menunewapp:cafe-menuold

    When a pod is replaced, the new one carries the label too, and the Service stands for it. The note stays right.

  6. 6 Now look for the Service's address. No pod has it, and no single computer answers to it. Yet requests sent there get the menu. Where do they go?10.96.0.20?node-1node-2node-3node-4otherapps

    Now look for the Service's address. No pod has it, and no single computer answers to it. Yet requests sent there get the menu. Where do they go?

  7. Quick check

    Rono's café gets busy.You ask for 5 podsinstead of 3. Doesthe order app needa new addresson its note?

    Rono's café gets busy.

    Show the answer

    No. The 2 new pods carry the label, so the Service stands for them too, and its address stays the same.

  8. Go further

    The real names of the Service.10.96.0.20ClusterIP, cluster IPthe kind of Service you made.Its address, the cluster IP,works inside the cluster onlyapp:cafe-menuselectorthe part of a Service thatnames the label to look for

    The real names of the Service.

Next episode How a Kubernetes Service address leads to one of your pods

Share this comic

More comics