Class KubernetesLookup

  • All Implemented Interfaces:
    org.apache.logging.log4j.core.lookup.StrLookup

    @Plugin(name="k8s",
            category="Lookup")
    public class KubernetesLookup
    extends org.apache.logging.log4j.core.lookup.AbstractLookup
    Retrieves various attributes from the Kubernetes server.

    The supported keys are listed in the following table:

    Supported keys
    Key Description
    "accountName" the name of the account
    "annotations" the annotations of the Kubernetes pod
    "containerId" the id of the Kubernetes container
    "containerName" the name of the Kubernetes container
    "host" the host name of the Kubernetes pod
    "hostIp" the IP of the Kubernetes pod
    "imageId" the id of the Kubernetes container image
    "imageName" the name of the Kubernetes container image
    "labels" the labels of the Kubernetes pod
    "labels.<name>" the value of the "<name>" label of the Kubernetes pod
    "masterUrl" the master URL of the Kubernetes cluster
    "namespaceAnnotations" the annotations of the namespace
    "namespaceId" the id of the namespace
    "namespaceLabels" the labels of the namespace
    "namespaceName" the name of the namespace
    "podId" the id of the pod
    "podIp" the IP of the pod
    "podName" the name of the pod
    • Field Summary

      • Fields inherited from interface org.apache.logging.log4j.core.lookup.StrLookup

        CATEGORY
    • Constructor Summary

      Constructors 
      Constructor Description
      KubernetesLookup()
      Default constructor, called by reflection.
    • Constructor Detail

      • KubernetesLookup

        public KubernetesLookup()
        Default constructor, called by reflection.
    • Method Detail

      • createClient

        protected io.fabric8.kubernetes.client.KubernetesClient createClient()
        Creates a Kubernetes client used to retrieve K8S configuration.

        Used in tests to provide a mock client.

        Returns:
        A Kubernetes client.
      • lookup

        public String lookup​(org.apache.logging.log4j.core.LogEvent event,
                             String key)