<p>I understand how to set targetPort as integer value when defining service in k8s.</p>

<p>However, I'm a little confused about how to set targetPort with string value.</p>

<p>Is there any example about this?</p>

<p>Thanks,</p>

<p>This Service is for Prometheus. In the following manifest, you first have to define <code>web</code> in the Deployment before you can refer to it as a string in <code>targetPort</code>.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    prometheus: k8s
  name: prometheus-k8s
  namespace: monitoring
spec:
  ports:
  - name: web
    nodePort: 30900
    port: 9090
    protocol: TCP
    targetPort: web
  selector:
    prometheus: k8s
  type: NodePort
</code></pre>
