Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22337

Get output of Kubernetes pod running a python file

$
0
0

I am running a python script on a docker container inside a kubernetes pod, my script is a mqtt script that when I will be receving a message it prints out the message (i want to be able to save it in the future or send it to another .txt).Right now i am not receiving any outputs in my logs, why is this?I am getting outputs but just about the client connection, new clients connecting etc. I want to get the messages, right now I am just sending "hello", i am receiving this mqtt messages if i do in my terminal mosquitto_pub/mosquitto_sub but not on the output of the pod script. Thank you :)

Dockerfile:

FROM docker.deere.com/python:3.8-slimRUN pip install paho-mqttCOPY subscriber.py /subscriber.pyCMD ["python", "./subscriber.py"]

Kubernetes deployment:apiVersion: apps/v1kind: Deploymentmetadata:name: mosquitto-brokerspec:replicas: 1selector:matchLabels:app: mqtt-brokertemplate:metadata:labels:app: mqtt-brokerspec:containers:- name: mqtt-broker-initimage: my-mosquitto:latestports:- containerPort: 1883- name: mqtt-subsimage: mosquitto-subscriber:latest

python script:

import paho.mqtt.client as mqttdef on_connect(client, userdata, flags, rc):    print("Connected with result code " + str(rc))    client.subscribe("test/topic")def on_message(client, userdata, msg):    print("Received message: " + msg.payload.decode())client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, "SubscriberTest")client.on_connect = on_connectclient.on_message = on_messageclient.connect("172.30.0.130", 30988, 60)client.loop_forever()

pod output:

❯  kubectl logs deployment/mosquitto-brokerFound 4 pods, using pod/mqtt-broker-68c7545bc8-4fs86Defaulted container "mqtt-broker" out of: mqtt-broker, mosquitto-subs1708114383: mosquitto version 2.0.18 starting1708114383: Config loaded from /mosquitto/config/mosquitto.conf.1708114383: Opening ipv4 listen socket on port 1883.1708114383: Opening ipv6 listen socket on port 1883.1708114383: mosquitto version 2.0.18 running1708114429: New connection from 10.244.0.1:32866 on port 1883.1708114429: New client connected from 10.244.0.1:32866 as SubscriberTest (p2, c1, k60).1708114471: New connection from 10.244.0.1:23628 on port 1883.1708114471: New client connected from 10.244.0.1:23628 as auto-8F54FBAD-6D14-FBB1-6C0B-9E9A5E6101AB (p2, c1, k60).1708114471: Client auto-8F54FBAD-6D14-FBB1-6C0B-9E9A5E6101AB disconnected.1708114474: New connection from 10.244.0.1:14961 on port 1883.1708114474: Client SubscriberTest already connected, closing old connection.1708114474: New client connected from 10.244.0.1:14961 as SubscriberTest (p2, c1, k60).1708114475: New connection from 10.244.0.1:18285 on port 1883.1708114475: Client SubscriberTest already connected, closing old connection.1708114475: New client connected from 10.244.0.1:18285 as SubscriberTest (p2, c1, k60).1708114476: New connection from 10.244.0.1:11965 on port 1883.1708114476: Client SubscriberTest already connected, closing old connection.1708114476: New client connected from 10.244.0.1:11965 as SubscriberTest (p2, c1, k60).1708114477: New connection from 10.244.0.1:50342 on port 1883.1708114477: Client SubscriberTest already connected, closing old connection.1708114477: New client connected from 10.244.0.1:50342 as SubscriberTest (p2, c1, k60).1708114604: New connection from 10.244.0.1:48118 on port 1883.1708114604: New client connected from 10.244.0.1:48118 as auto-6CE6C67F-7CC7-53BD-2627-F3A483F7E774 (p2, c1, k60).1708114604: Client auto-6CE6C67F-7CC7-53BD-2627-F3A483F7E774 disconnected.1708115507: New connection from 10.244.0.1:33888 on port 1883.1708115507: Client SubscriberTest already connected, closing old connection.1708115507: New client connected from 10.244.0.1:33888 as SubscriberTest (p2, c1, k60).1708115512: New connection from 10.244.0.1:60569 on port 1883.1708115512: Client SubscriberTest already connected, closing old connection.1708115512: New client connected from 10.244.0.1:60569 as SubscriberTest (p2, c1, k60).1708115565: New connection from 10.244.0.1:14096 on port 1883.1708115565: New client connected from 10.244.0.1:14096 as auto-451A6E10-1B48-73E8-5BA8-A7606A5D4AC9 (p2, c1, k60).1708115565: Client auto-451A6E10-1B48-73E8-5BA8-A7606A5D4AC9 disconnected.1708115567: New connection from 10.244.0.1:15433 on port 1883.1708115567: New client connected from 10.244.0.1:15433 as auto-3B09DB6C-5735-EEF5-2F17-279A7221E179 (p2, c1, k60).1708115567: Client auto-3B09DB6C-5735-EEF5-2F17-279A7221E179 disconnected.1708115929: New connection from 10.244.0.1:23931 on port 1883.1708115929: New client connected from 10.244.0.1:23931 as auto-7ECB485C-F10A-3DB3-9CB4-DF4F481EFF46 (p2, c1, k60).1708115929: Client auto-7ECB485C-F10A-3DB3-9CB4-DF4F481EFF46 disconnected.1708115939: New connection from 10.244.0.1:33648 on port 1883.1708115939: New client connected from 10.244.0.1:33648 as auto-A4247317-B4D0-1B57-A339-E29F57E70313 (p2, c1, k60).1708115939: Client auto-A4247317-B4D0-1B57-A339-E29F57E70313 disconnected.

Viewing all articles
Browse latest Browse all 22337

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>