<p>Hello everyone i am trying kubernetes and have the version that comes with docker desktop for windows and i cant seem to access a service which has type nodeport . Following are the related info</p>

<pre><code>docker version:

Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false



Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false



kubernetes version:

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:25:46Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
</code></pre>

<p>my deployment file:(deployment.yml)</p>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Deployment
metadata: 
  name: tomcat-app
spec:
  replicas: 5
  template:
    metadata:
      labels:
        app: tomcat-app
    spec:
      containers:
        - name: tomcat-app
          image: tomcatapp:v1.0.0
          ports:
            - containerPort: 80


---
kind: Service
apiVersion: v1
metadata:
  name: tomcatappservice
spec:

  type: NodePort
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 80
  selector:
    app: tomcat-app
</code></pre>

<p>ran it with </p>

<pre><code>kubectl create -f deployment.yml
</code></pre>

<p>cant seem to access the tomcat server at localhost: given by kubernetes also tried explicitly giving a port in deployment file but still cant get it to work</p>

<ol>
<li>You must have two tags <code>nodePort: 30007</code> and <code>type: NodePort</code>
Your service yaml should be like this:</li>
</ol>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: tomcatappservice
spec:
  type: NodePort
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 80
      nodePort: 30007
  selector:
    app: tomcat-app
</code></pre>

<ol start="2">
<li>Test it by <code>kubectl get services</code>, and if it succeed, you will see something like <code>80:30007/TCP</code></li>
</ol>

<pre><code>$ kubectl get services
NAME           TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
hello          NodePort       10.96.92.53    &lt;none&gt;        80:30007/TCP   3d3h
</code></pre>

<ol start="3">
<li>Access your service.</li>
</ol>

<pre><code>$ kubectl describe nodes | grep InternalIP -n1
26-Addresses:
27:  InternalIP:  172.17.0.3
28-  Hostname:    kind2-control-plane
</code></pre>

<p>or</p>

<pre><code>$ kubectl get nodes --output json
{
    "apiVersion": "v1",
    "items": [
            ...
            "status": {
                "addresses": [
                    {
                        "address": "172.17.0.3",
                        "type": "InternalIP"
                    },
                    {
                        "address": "kind2-control-plane",
                        "type": "Hostname"
                    }
                ],
    ...
}

$ kubectl get nodes --output jsonpath='{.items[*].status.addresses}'
[map[address:172.17.0.3 type:InternalIP] map[address:kind2-control-plane type:Hostname]]
</code></pre>

<p>In the above examples, URL is <a href="http://127.17.0.3:30007" rel="nofollow noreferrer">http://127.17.0.3:30007</a>.</p>
