title: Start sprinboot in minkube with custom context url as environnement variable
body: <p>I have a springboot app which I want to deploy on Kubernetes (I'm using minikube) with a custom context path taken from the environment variables.</p>
  
  <p>I've compiled an app.war file. exported an environment variable in Linux as follow: </p>
  
  <p><code>export SERVER_SERVLET_CONTEXT_PATH=/app</code> </p>
  
  <p>And then started my app on my machine as follow: </p>
  
  <p><code>java -jar app.war --server.servlet.context-path=$(printenv CONTEXT_PATH)</code></p>
  
  <p>and it works as expected, I can access my app throw browser using the url <strong>localhost:8080/app/</strong></p>
  
  <p>I want to achieve the same thing on minikube so I prepared those config files:</p>
  
  <hr>
  
  <ul>
  <li><p>Dockerfile:</p>
  
  <pre><code>FROM openjdk:8
  ADD app.war app.war
  EXPOSE 8080
  ENTRYPOINT ["java", "-jar", "app.war", "--server.servlet.context-path=$(printenv CONTEXT_PATH)"]
  </code></pre></li>
  </ul>
  
  <hr>
  
  <ul>
  <li><p>deployment config file:</p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: esse-deployment-1
    labels:
      app: esse-1
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: esse-1
    template:
      metadata:
        labels:
          app: esse-1
      spec:
        containers:
        - image: mysql:5.7
          name: esse-datasource
          ports:
          - containerPort: 3306
          env: 
          - name: MYSQL_ROOT_PASSWORD
            value: root 
        - image: esse-application
          name: esse-app
          imagePullPolicy: Never
          ports:
          - containerPort: 8080
          env:
          - name: server.servlet.context-path
            value: /esse-1
        volumes:
          - name: esse-1-mysql-persistent-storage
            persistentVolumeClaim:
              claimName: mysql-persistent-storage-claim
  
  ---
  
  apiVersion: v1
  kind: Service
  metadata:
    name: esse-service-1
    labels:
      app: esse-1
  spec:
    selector:
      app: esse-1
    ports:
      - protocol: TCP
        port: 8080
        targetPort: 8080
    type: NodePort
  </code></pre></li>
  </ul>
  
  <p>However, the java container inside the pod fails to start and here's the exception is thrown by spring: </p>
  
  <blockquote>
    <p>Initialization of bean failed; nested exception is
    java.lang.IllegalArgumentException: ContextPath must start with '/'
    and not end with '/'</p>
  </blockquote>