<p>I am trying to deploy a "Hello world" Spring Boot app on Kubernetes (Minikube).
The app is really simple, just one method, which is mapped on a GET resource. I even do not specify a port.</p>

<p>I am now trying to deploy the app on Minikube, and making it available using a Service:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: server
spec:
  selector:
    app: server
  ports:
  - protocol: TCP
    port: 8080
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: server
spec:
  selector:
      matchLabels:
        app: server
  replicas: 3
  template:
    metadata:
      labels:
        app: server
    spec:
      containers:
        - name: server
          image: kubernetes-server:latest
          imagePullPolicy: Never
          ports:
            - name: http
              containerPort: 8080
</code></pre>

<p>If I start the deployment using this configuration (i. e. the service is started first, then the Deployment), the pods fail during startup.
In the logs, I can find the following message:</p>

<pre><code>***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target         
org.springframework.boot.autoconfigure.web.ServerProperties@42f93a98 failed:

    Property: server.port
    Value: tcp://10.98.151.181:8080
    Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'port'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.lang.Integer]
</code></pre>

<p>Note: 10.98.151.181 is the cluster IP of the Service, as a can see in the Minikube dashboard.</p>

<p>If I first trigger the actual Deployment, the app starts successfully, and after that, I can start the Service.
However, the official documentation recommends to start the service first, and after that the deplyoment: <a href="https://kubernetes.io/docs/concepts/configuration/overview/#services" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/overview/#services</a></p>

<p>For me, it looks like the Service sets a property <em>server.port</em> as environment variable, and the Spring Boot app, which start after the Service, interprets that accidentially as the Spring <em>server.port</em>.</p>

<p>Any ideas how to solve that?</p>

<blockquote>
  <p>For me, it looks like the Service sets a property server.port as environment variable</p>
</blockquote>

<p>No, kubernetes it is exposing "docker compatible" <a href="https://docs.docker.com/network/links/#environment-variables" rel="noreferrer">link env-vars</a> which, because your <code>Service</code> is named <code>server</code>, end up being <code>SERVER_PORT=tcp://thing:8080</code> because it is trying to be "helpful"</p>

<p>The solution is either give your <code>Service</code> a much more descriptive name, or mask-off the offending env-var:</p>

<pre class="lang-yaml prettyprint-override"><code>containers:
- name: server
  env:
  - name: SERVER_PORT
    value: ''  # you can try the empty string,
    # or actually place the port value with
    # value: '8080'
    # ensure it is a **string** and not `value: 8080`
</code></pre>
