App Code:
from flask import Flask
import instana
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World with Instana!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
cat requirements.txt
flask
instana
Dockerfile:
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py .
EXPOSE 8080
CMD ["python", "app.py"]
---------
docker build -t mbx1010/webapp:latest .
docker push mbx1010/webapp:latest
Kubernetes Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp
spec:
replicas: 1
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: mbx1010/webapp:latest
ports:
- containerPort: 8080
env:
- name: INSTANA_SERVICE_NAME
value: "webapp"
- name: AUTOWRAPT_BOOTSTRAP
value: "instana"
---
apiVersion: v1
kind: Service
metadata:
name: webapp
spec:
type: LoadBalancer
selector:
app: webapp
ports:
- protocol: TCP
port: 8080
targetPort: 8080
Test deployment with a Load Balancer Services , the Service Name is webapp, if you deploy this in multiple namespaces , and you do the curl against :
Curl to Service 1
while true
do
curl http://192.168.178.213:8080/
sleep 10
done
------
Curl to Service 2
while true
do
curl http://192.168.178.212:8080/
sleep 10
done