Inverter Deployment Task
This is the fourth and most critical component in our data pipeline. In this tutorial, you will deploy the inverter, a custom application that simulates a SunSpec-compliant solar inverter. It acts as the final destination for our data, consuming messages from the Kafka topic you set up earlier and exposing the data via the Modbus protocol on port 502.
This task is designed to teach you how to deploy a Kubernetes application that consumes data from a message queue and exposes a non-HTTP protocol (Modbus/TCP) to the outside world using a NodePort service.
In this tutorial, you will be tasked to:
Deploy a consumer application that connects to Kafka.
Configure the application to run on a specific worker node (
nano).Use advanced environment variable injection to get the host node's IP address.
Create a
NodePortservice with a specificexternalTrafficPolicyto correctly route external traffic.Verify that the inverter is running and consuming data from the Kafka topic.
Before you start
Make sure that:
The Zookeeper, Kafka, and Streamer deployments are all running successfully.
The
ghcr-pull-secretexists in the cluster for pulling private images.You are SSHed into the
k3smainnode and have switched to the shared user account.
Part 1: Create the Inverter Deployment Manifest
Your first goal is to create a Kubernetes deployment file named inverter-deployment.yaml.
Deployment Requirements
The Inverter instance must be configured with the following specifications:
Deployment Name: The deployment must be named
inverter.Node Affinity: This is important. The pod must be scheduled to run on the node named
nano, notk3smain.Container Image: Use the
ghcr.io/decsresearch/c2sr-bootcamp-inverter:latestimage.Image Pull Secret: Reference the
ghcr-pull-secretto authorize pulling the image.Port: The container must expose the Modbus port,
502.Environment Configuration:
KAFKA_HOST: The name of the Kafka service (kafka-service).KAFKA_INPUT_TOPIC: The topic to consume from. This must match the topic the streamer is producing to (nano).NODE_NAME: A logical name for the inverter, set tonano.NODE_IP: This must be set dynamically to the IP of the host node the pod is running on. This is achieved usingvalueFromand afieldRef.INVERTER_HOST_IP: The IP address the inverter service should listen on inside the container (0.0.0.0).INVERTER_PORT: The port the inverter service should listen on inside the container (502).
Skeleton File for Deployment
Create a file named inverter-deployment.yaml and fill it out according to the requirements above.
Part 2: Expose the Inverter with a Service
To allow the SunSpec client (which runs outside the cluster) to connect to the inverter's Modbus port, you must create a NodePort service.
Service Requirements
The Service must:
Have the name
inverter-service.Be of type
NodePort.Set the
externalTrafficPolicytoLocal. This ensures traffic is only sent to the pod on the node that receives the request, which is necessary for this setup.Expose the TCP protocol on port
502, mapped totargetPort502and a staticnodePortof30502.Use a selector to correctly identify the inverter pod (
app: inverter).
Skeleton File for Service
Create a second file named inverter-service.yaml and complete the skeleton below.
Part 3: Deployment and Verification
Once you have created both YAML files, apply them and check the logs. The logs will confirm that the inverter has connected to Kafka and is processing messages from the streamer.
Apply the manifests:
kubectl apply -f inverter-deployment.yamlkubectl apply -f inverter-service.yamlVerify the deployment:
kubectl get pods -l app=inverter -o wide(Use-o wideto confirm it is running on thenanonode).Check for data consumption:
kubectl logs -f <pod name>
If the logs show the inverter is successfully consuming messages, you are ready for the final step: connecting with the SunSpec client.