title: How to debug kafka in kubernetes (minikube) using telepresence
body: <p>I have Kafka running inside Minikube. Kafka works fine, but I want to use it in my Java app that is located on my local machine (not minikube). I know that it's possible to proxy requests from a local machine to a kubernetes cluster using Telepresence.</p>
  <p>I'm trying to run <code>telepresence intercept -n kafka kafka-service 9092:9092</code>, but the error occurs <code>telepresence: error: workload &quot;kafka-service.kafka&quot; not found</code>.
  I know the actual addresses of kafka brokers look like <code>kafka-0.kafka-service.kafka.svc.cluster.local:9092</code>. However, I don't understand how to make it work.</p>
  <p>kafka.yaml</p>
  <pre><code>apiVersion: v1
  kind: Namespace
  metadata:
    name: kafka
  ---
  apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: kafka-pv-volume
    labels:
      type: local
  spec:
    storageClassName: manual
    capacity:
      storage: 10Gi
    accessModes:
      - ReadWriteOnce
    hostPath:
      path: '/mnt/data'
  ---
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: kafka-pv-claim
    namespace: kafka
  spec:
    storageClassName: manual
    accessModes:
      - ReadWriteOnce
    resources:
      requests:
        storage: 3Gi
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: kafka-service
    namespace: kafka
    labels:
      app: kafka
  spec:
    selector:
      app: kafka
    clusterIP: None
    ports:
      - port: 9092
        protocol: TCP
        targetPort: 9092
  ---
  apiVersion: apps/v1
  kind: StatefulSet
  metadata:
    name: kafka
    labels:
      app: kafka
    namespace: kafka
  spec:
    serviceName: kafka-service
    replicas: 3
    selector:
      matchLabels:
        app: kafka
    template:
      metadata:
        labels:
          app: kafka
      spec:
        volumes:
          - name: kafka-storage
            persistentVolumeClaim:
              claimName: kafka-pv-claim
        containers:
          - name: kafka-container
            image: evmusonov/kafka-kraft
            resources:
            ports:
              - containerPort: 9092
              - containerPort: 9093
            env:
              - name: REPLICAS
                value: '3'
              - name: SERVICE
                value: kafka-service
              - name: NAMESPACE
                value: kafka
              - name: SHARE_DIR
                value: /mnt/kafka
            volumeMounts:
              - name: kafka-storage
                mountPath: /mnt/kafka
  </code></pre>
  <p>Dockerfile:</p>
  <pre><code>FROM openjdk:11
  
  ENV KAFKA_VERSION=3.2.0
  ENV SCALA_VERSION=2.13
  ENV KAFKA_HOME=/opt/kafka
  ENV PATH=${PATH}:${KAFKA_HOME}/bin
  
  LABEL name=&quot;kafka&quot; version=${KAFKA_VERSION}
  
  RUN wget -O /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz https://downloads.apache.org/kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz \
   &amp;&amp; tar xfz /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt \
   &amp;&amp; rm /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz \
   &amp;&amp; ln -s /opt/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ${KAFKA_HOME} \
   &amp;&amp; rm -rf /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz
  
  COPY ./entrypoint.sh /
  RUN [&quot;chmod&quot;, &quot;+x&quot;, &quot;/entrypoint.sh&quot;]
  ENTRYPOINT [&quot;/entrypoint.sh&quot;]
  </code></pre>
  <p>And the <code>entrypoint.sh</code> script:</p>
  <pre><code>#!/bin/bash
  
  NODE_ID=${HOSTNAME:6}
  LISTENERS=&quot;PLAINTEXT://:9092,CONTROLLER://:9093&quot;
  ADVERTISED_LISTENERS=&quot;PLAINTEXT://kafka-$NODE_ID.$SERVICE.$NAMESPACE.svc.cluster.local:9092&quot;
  
  CONTROLLER_QUORUM_VOTERS=&quot;&quot;
  for i in $( seq 0 $REPLICAS); do
      if [[ $i != $REPLICAS ]]; then
          CONTROLLER_QUORUM_VOTERS=&quot;$CONTROLLER_QUORUM_VOTERS$i@kafka-$i.$SERVICE.$NAMESPACE.svc.cluster.local:9093,&quot;
      else
          CONTROLLER_QUORUM_VOTERS=${CONTROLLER_QUORUM_VOTERS::-1}
      fi
  done
  
  mkdir -p $SHARE_DIR/$NODE_ID
  
  if [[ ! -f &quot;$SHARE_DIR/cluster_id&quot; &amp;&amp; &quot;$NODE_ID&quot; = &quot;0&quot; ]]; then
      CLUSTER_ID=$(kafka-storage.sh random-uuid)
      echo $CLUSTER_ID &gt; $SHARE_DIR/cluster_id
  else
      CLUSTER_ID=$(cat $SHARE_DIR/cluster_id)
  fi
  
  sed -e &quot;s+^node.id=.*+node.id=$NODE_ID+&quot; \
  -e &quot;s+^controller.quorum.voters=.*+controller.quorum.voters=$CONTROLLER_QUORUM_VOTERS+&quot; \
  -e &quot;s+^listeners=.*+listeners=$LISTENERS+&quot; \
  -e &quot;s+^advertised.listeners=.*+advertised.listeners=$ADVERTISED_LISTENERS+&quot; \
  -e &quot;s+^log.dirs=.*+log.dirs=$SHARE_DIR/$NODE_ID+&quot; \
  /opt/kafka/config/kraft/server.properties &gt; server.properties.updated \
  &amp;&amp; mv server.properties.updated /opt/kafka/config/kraft/server.properties
  
  kafka-storage.sh format -t $CLUSTER_ID -c /opt/kafka/config/kraft/server.properties
  
  exec kafka-server-start.sh /opt/kafka/config/kraft/server.properties
  </code></pre>
  <p>Spring-boot application.properties</p>
  <pre><code>spring.kafka.producer.bootstrap-servers = kafka-0.kafka-service.kafka.svc.cluster.local:9092,kafka-1.kafka-service.kafka.svc.cluster.local:9092,kafka-2.kafka-service.kafka.svc.cluster.local:9092
  spring.kafka.producer.key-serializer = org.apache.kafka.common.serialization.StringSerializer
  spring.kafka.producer.value-serializer = org.apache.kafka.common.serialization.StringSerializer
  
  spring.kafka.consumer.bootstrap-servers = kafka-0.kafka-service.kafka.svc.cluster.local:9092,kafka-1.kafka-service.kafka.svc.cluster.local:9092,kafka-2.kafka-service.kafka.svc.cluster.local:9092
  spring.kafka.consumer.key-serializer = org.apache.kafka.common.serialization.StringSerializer
  spring.kafka.consumer.value-serializer = org.apache.kafka.common.serialization.StringSerializer
  spring.kafka.consumer.group-id = &quot;custom&quot;
  </code></pre>