LAB11b: Label Selector

LAB60: Labeling Resources correctly

Demonstrate why labels matter — especially when two Services accidentally point to the same Pods because they share the same labels.

Two apps:

  • hello.xyz → “Hello! Nice to meet you!”

  • bye.xyz → “Bye! See you.”

  • Docker images:

    • openlabfree/hello-hello

    • openlabfree/bye-bye

  • Namespace: dev


chevron-rightApp Source Code (Hello)hashtag
from flask import Flask
import socket
import os

app = Flask(__name__)

@app.route("/")
def index():
    return f"""
    <h1>Hello! Nice to meet you!</h1>
    <h3>POD Info</h3>
    Hostname: {socket.gethostname()}<br>
    <h3>Service Info</h3>
    SERVICE_NAME: {os.environ.get('SERVICE_NAME', 'N/A')}<br>
    <h3>Deployment Info</h3>
    DEPLOYMENT: hello-deploy<br>
    """

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)
chevron-rightApp Source Code (Bye)hashtag
from flask import Flask
import socket
import os

app = Flask(__name__)

@app.route("/")
def index():
    return f"""
    <h1>Bye! See you.</h1>
    <h3>POD Info</h3>
    Hostname: {socket.gethostname()}<br>
    <h3>Deployment Info</h3>
    DEPLOYMENT: bye-deploy<br>
    <h3>Service Info</h3>
    SERVICE_NAME: {os.environ.get('SERVICE_NAME', 'N/A')}<br>
    """

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)
chevron-rightDockerfilehashtag

--- ## First of all, install NGINX Ingress

Verify if ingress controller is running

Patch ingress controller to NodePort type, optionally you can fix the port

Patch Command (HTTP + HTTPS fixed ports)

Scenario 1: WRONG Label

chevron-right`label-conflict-demo.yaml`hashtag

Apply it ```bash kubectl apply -f label-conflict-demo.yaml

Or with curl:

Scenario 2: Correct Label

chevron-right`label-correct-demo.yaml`hashtag

Apply it: ```bash kubectl apply -f label-correct-demo.yaml

Or with curl:

Last updated