<p>I have created a ClusterIP service according to configuration files below, however I can't seem to get the URL from minikube for that service</p>

<pre class="lang-sh prettyprint-override"><code>k create -f service-cluster-definition.yaml
➜ minikube service myapp-frontend --url                                           
😿  service default/myapp-frontend has no node port
</code></pre>

<p>And if I try to add NodePort into the <strong>ports</strong> section of service-cluster-definition.yaml it complains with error, that such key is deprecated.</p>

<h3>What am I missing or doing wrong?</h3>

<p><strong>service-cluster-definition.yaml</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: myapp-frontend
spec:
  type: ClusterIP
  ports:
    - targetPort: 80
      port: 80
  selector:
    app: myapp
    type: etl

</code></pre>

<p><strong>deployment-definition.yaml</strong></p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
  labels:
    app: myapp
    env: experiment
    type: etl
spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        env: experiment
        type: etl
    spec:
      containers:
        - name: nginx-container
          image: nginx:1.7.1
  replicas: 3
  selector:
    matchLabels:
      type: etl
</code></pre>

<pre><code>➜ k get pods --selector="app=myapp,type=etl" -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATES
myapp-deployment-59856c4487-2g9c7   1/1     Running   0          45m   172.17.0.9   minikube   &lt;none&gt;           &lt;none&gt;
myapp-deployment-59856c4487-mb28z   1/1     Running   0          45m   172.17.0.4   minikube   &lt;none&gt;           &lt;none&gt;
myapp-deployment-59856c4487-sqxqg   1/1     Running   0          45m   172.17.0.8   minikube   &lt;none&gt;           &lt;none&gt;


(⎈ |minikube:default)
Projects/experiments/kubernetes 
➜ k version     
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:14:22Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:07:13Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
(⎈ |minikube:default)
</code></pre>

<h3>First let's clear some concepts from <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="noreferrer">Documentation</a>:</h3>

<blockquote>
  <ul>
  <li><p>ClusterIP: Exposes the Service on a cluster-internal IP.
    Choosing this value <strong>makes the Service only reachable from within</strong> the cluster.</p></li>
  <li><p><a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="noreferrer">NodePort</a>: Exposes the Service on each Node’s IP at a static port (the NodePort).
  You’ll be able to contact the NodePort Service, <strong>from outside the cluster</strong>, by requesting  <code>NodeIP:NodePort</code>.</p></li>
  </ul>
</blockquote>

<hr>

<p><strong>Question 1:</strong></p>

<blockquote>
  <p>I have created a ClusterIP service according to configuration files below, however I can't seem to get the URL from minikube for that service.</p>
</blockquote>

<ul>
<li>Since Minikube is a virtualized environment on a single host we tend to forget that the cluster is isolated from the host computer. If you set a service as <code>ClusterIP</code>, Minikube will not give external access.</li>
</ul>

<p><strong>Question 2:</strong></p>

<blockquote>
  <p>And if I try to add NodePort into the  <strong>ports</strong>  section of <em>service-cluster-definition.yaml</em> it complains with error, that such key is deprecated.</p>
</blockquote>

<ul>
<li>Maybe you were pasting on the wrong position. You should just substitute the field <code>type: ClusterIP</code> for <code>type: NodePort</code>. Here is the correct form of your yaml:</li>
</ul>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: myapp-frontend
spec:
  type: NodePort
  ports:
    - targetPort: 80
      port: 80
  selector:
    app: myapp
    type: etl
</code></pre>

<hr>

<p><strong>Reproduction:</strong></p>

<pre><code>user@minikube:~$ kubectl apply -f deployment-definition.yaml 
deployment.apps/myapp-deployment created

user@minikube:~$ kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
myapp-deployment-59856c4487-7dw6x   1/1     Running   0          5m11s
myapp-deployment-59856c4487-th7ff   1/1     Running   0          5m11s
myapp-deployment-59856c4487-zvm5f   1/1     Running   0          5m11s

user@minikube:~$ kubectl apply -f service-cluster-definition.yaml 
service/myapp-frontend created

user@minikube:~$ kubectl get service myapp-frontend
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
myapp-frontend   NodePort    10.101.156.113   &lt;none&gt;        80:32420/TCP   3m43s

user@minikube:~$ minikube service list
|-------------|----------------|-----------------------------|-----|
|  NAMESPACE  |      NAME      |         TARGET PORT         | URL |
|-------------|----------------|-----------------------------|-----|
| default     | kubernetes     | No node port                |     |
| default     | myapp-frontend | http://192.168.39.219:32420 |     |
| kube-system | kube-dns       | No node port                |     |
|-------------|----------------|-----------------------------|-----|

user@minikube:~$ minikube service myapp-frontend --url
http://192.168.39.219:32420

user@minikube:~$ curl http://192.168.39.219:32420
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
...{{output suppressed}}...
</code></pre>

<ul>
<li>As you can see, with the service set as <code>NodePort</code> the minikube start serving the app using <code>MinikubeIP:NodePort</code> routing the connection to the matching pods.

<ul>
<li>Note that <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="noreferrer">nodeport</a> will be chosen by default between 30000:32767</li>
</ul></li>
</ul>

<p>If you have any question let me know in the comments.</p>
