<p>I'm trying to deploy a docker container to Kubernetes using YAML file (local system).</p>

<p>Part 1: Docker container (Working fine)</p>

<ul>
<li>I am able to run the container and push into docker hub</li>
<li>Able to access container application over a browser.</li>
</ul>

<p>Part 2: Kubernetes (Not working)</p>

<ul>
<li>Wrote deployment.yaml file that includes both deployment and service</li>
<li>Deployment:  It is creating pod successfully</li>
<li>Service: Added service and trying to access the application over a browser but it is not working

<blockquote>
  <p>Error: Site can't be reached</p>
</blockquote></li>
</ul>

<p>Docker:</p>

<ul>
<li>Container pushed into docker hub

<ul>
<li>name: $ID/tomcat-jenkins</li>
<li>version: 3</li>
</ul></li>
</ul>

<p>Kubernetes:</p>

<ul>
<li>deployment.yaml</li>
</ul>

<pre><code>    apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
    kind: Deployment
    metadata:
      name: jenkins
    spec:
      selector:
        matchLabels:
          app: tomcat
      replicas: 2 # tells deployment to run 2 pods matching the template
      template:
        metadata:
          labels:
            app: tomcat
        spec:
          containers:
          - name: tomcat-jenkins
            image: $DOCKER-ID/tomcat-jenkins:3
            ports:
            - containerPort: 80
    # Service
    apiVersion: v1
    kind: Service
    metadata:
      name: jenkins
    spec:
      selector:
        app: tomcat
      ports:
      - protocol: TCP
        port: 80
        targetPort: 80
        nodePort: 31011
      type: NodePort
</code></pre>

<p>I am not able to access the application after deploying the container in Kubenetes pod.</p>

<p>I'm not sure whether my deployment.yaml file contains some syntax errors.</p>

Its Soni
<p>As you are exposing the service on <strong>NodePort</strong> , then you can access it with the <a href="http://NodeIP:NodePort" rel="nofollow noreferrer">http://NodeIP:NodePort</a>` . the value of nodeport is 31011 for the above service.</p>

<p>Here is the a detail <a href="https://kubernetes.io/docs/tutorials/kubernetes-basics/expose/expose-intro/" rel="nofollow noreferrer">tutorail</a> which explain exposing the service on k8s.</p>

<blockquote>
  <p>ClusterIP (default) - Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster.</p>
  
  <p>NodePort - Exposes the Service on the same port of each selected Node in the cluster using NAT. Makes a Service accessible from outside the cluster using :. Superset of ClusterIP.</p>
  
  <p>LoadBalancer - Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the Service. Superset of NodePort</p>
</blockquote>
