-1

My question is totally simple that is related to kubernetes awesome tool called KinD. I am using KinD for my flask application:

enter image description here

import os
import requests
from flask import Flask
from jaeger_client import Config
from flask_opentracing import FlaskTracing

app = Flask(__name__)
config = Config(
    config={
        'sampler':
        {'type': 'const',
         'param': 1},
                        'logging': True,
                        'reporter_batch_size': 1,}, 
                        service_name="service")
jaeger_tracer = config.initialize_tracer()
tracing = FlaskTracing(jaeger_tracer, True, app)

def get_counter(counter_endpoint):
    counter_response = requests.get(counter_endpoint)
    return counter_response.text

def increase_counter(counter_endpoint):
    counter_response = requests.post(counter_endpoint)
    return counter_response.text

@app.route('/')
def hello_world():
    counter_service = os.environ.get('COUNTER_ENDPOINT', default="https://localhost:5000")
    counter_endpoint = f'{counter_service}/api/counter'
    counter = get_counter(counter_endpoint)

    increase_counter(counter_endpoint)

    return f"""Hello, World!

You're visitor number {counter} in here!\n\n"""
FROM python:3.7-alpine
RUN mkdir /app
RUN apk add --no-cache py3-pip python3 && \
    pip3 install flask Flask-Opentracing jaeger-client
WORKDIR /app
ADD ./app /app/
ADD ./requirements.txt /app/
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "/app/main.py"]

deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-flask-deployment
spec:
  selector:
    matchLabels:
      app: my-flask-pod
  replicas: 2
  template:
    metadata:
      labels:
        app: my-flask-pod
    spec:
      containers:
      - name: my-flask-container
        image: yusufkaratoprak/awsflaskeks:latest
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 5000

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: my-flask-service
spec:
  selector:
    app: my-flask-pod
  ports:
  - port: 6000
    targetPort: 5000
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 203.0.113.10

Configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 172.42.42.100-172.42.42.105 #Update this with your Nodes IP range 

Results:

enter image description here enter image description here

Everything looks good. When I write my browser: http://172.42.42.101:6000/

Result:

enter image description here

Also , I want to add my service events. Everything looks good : enter image description here

and Also I want to add @Kaan Mersin advise : I added 80 as default port.

enter image description here

Penguen
  • 16,836
  • 42
  • 130
  • 205
  • 1
    Did you try with ports 80 or 8080? Usually ports like 6000 etc not allowed sometimes form browser? – arjain13 Apr 04 '21 at 09:40
  • @arjain13 Let me try ir thank you! – Penguen Apr 04 '21 at 09:50
  • @arjain13 it doesn't work. The same result. Is there any issue for firewall? – Penguen Apr 04 '21 at 10:56
  • Why not use `k3d` which includes a load balancer? Also, the fact you're using WSL is a problem because you need to port forward **it** into your windows host (you should first test curl from WSL before attempting to use Chrome) – OneCricketeer Apr 04 '21 at 18:21
  • Can you please use telnet or (curl -v telnet:// :) from one of the Kubernetes nodes to respective endpoints ? respectively pod ıp:port, service internal ıp:port and ingress ıp:port. With this way we can make problem scope more narrow. Because we even do not know application is healthy or not . @ALEXALEXIYEV – Kağan Mersin May 26 '21 at 18:43

2 Answers2

2

Actually for bare metal server you should use another solution except of LoadBalancer to expose your application such as NodePort, Ingress and so on. Because LoadBalancer service type just for Cloud providers like Google, Azure, AWS and etc.

Check official documentation for LoadBalancer

Follow below way with thinking that you are using NodePort instead of LoadBalancer, NodePort service type also load balance traffic between pods ıf you are looking forward just balancing feature ;

You need to use http://172.42.42.101:30160 from outside of the host which is running containers on. Port 6000 is just accessible inside the cluster with internal IP (10.96.244.204 is in your case). Whenever you expose your deployment, automatically (also you can define manually) one of the NodePort (by default between 30000 - 32767)assign to the service for external request.

For service details, you need to run the below command. The command output will give you NodePort and another details.

kubectl describe services my-service

Please check related kubernetes documentation

Kağan Mersin
  • 391
  • 2
  • 9
  • Thank you for your great advice but unfortunately I am trying to use metalb with KinD. Otherwise, I agree with you nodeport a unique solution for bare metal if we think . – Penguen Apr 04 '21 at 16:26
1

The error Chrome is throwing is ERR_UNSAFE_PORT. Change your Service port to 80 and then hit http://172.42.42.101/. Alternatively you can choose any other port you like so long as Chrome doesn't consider it an unsafe port. See this answer on SuperUser for a list of unsafe ports.

Tyzbit
  • 166
  • 2
  • I updated my question and added 2 valuable results below. I used 80 as port but result is the same :( – Penguen Apr 04 '21 at 17:47
  • To clarify, the result is Chrome still throws an `ERR_UNSAFE_PORT` error? Double check your firewall on the workers and ensure the IP range you're giving MetalLB is valid for your network. – Tyzbit Apr 04 '21 at 18:17
  • Yes result is the same I updated my question above. – Penguen Apr 04 '21 at 18:30