Search code examples
kubernetessnmpkubernetes-networking

Send outbound SNMP alarms with static IP from pod in Kubernetes


I have a pod within a Kubernetes cluster that needs to send alarms via SNMP to an external network management system. However, the external system will only be able to identify the pod if it keeps a stable IP address. Considering the ephermal nature of pods, would it be possible to send/redirect requests to a system outside of the cluster with a static IP?

The information I could gather by now only proposed solutions on how to reach the pod from outside the cluster with e.g. Services. I found the following answer that suggests using an egress gateway, but not much information is provided on how to approach the issue.


Solution

  • One viable solution is to utilize an Egress Router resource defined here, which redirects traffic to a specified IP using a dedicated source IP address:

    apiVersion: v1
    kind: Pod
    metadata:
      name: egress-1
      labels:
        name: egress-1
      annotations:
        pod.network.openshift.io/assign-macvlan: "true" 
    spec:
      initContainers:
      - name: egress-router
        image: registry.redhat.io/openshift4/ose-egress-router
        securityContext:
          privileged: true
        env:
        - name: EGRESS_SOURCE 
          value: <egress_router>
        - name: EGRESS_GATEWAY 
          value: <egress_gateway>
        - name: EGRESS_DESTINATION 
          value: <egress_destination>
        - name: EGRESS_ROUTER_MODE
          value: init
      containers:
      - name: egress-router-wait
        image: registry.redhat.io/openshift4/ose-pod
    

    An example configuration looks like follows:

    apiVersion: v1
    kind: Pod
    metadata:
      name: egress-multi
      labels:
        name: egress-multi
      annotations:
        pod.network.openshift.io/assign-macvlan: "true"
    spec:
      initContainers:
      - name: egress-router
        image: registry.redhat.io/openshift4/ose-egress-router
        securityContext:
          privileged: true
        env:
        - name: EGRESS_SOURCE
          value: 192.168.12.99/24
        - name: EGRESS_GATEWAY
          value: 192.168.12.1
        - name: EGRESS_DESTINATION
          value: |
            203.0.113.25
        - name: EGRESS_ROUTER_MODE
          value: init
      containers:
      - name: egress-router-wait
        image: registry.redhat.io/openshift4/ose-pod
    

    The Egress Router pod is exposed by a Service and linked to the application that needs to send outbound SNMP traps:

    apiVersion: v1
    kind: Service
    metadata:
      name: egress-1
    spec:
      ports:
      - name: snmp
        port: 162
      type: ClusterIP
      selector:
        name: egress-1
    

    The application sends the SNMP trap to the ClusterIP/Service-Name of the Service exposing the Egress Router pod, and the pod redirects the request to the specified remote server. Once redirected, the source IP is changed to the Source IP specified in the Egress Router resource. For more information on implementing the egress router in redirection mode, see here.

    Note that depending on your network configuration, you might need to configure the assign-macvlan field to a different NIC interface and set it to the name of that interface, e.g. eth1.