<p>I need that tomcat is registered with my Node IP and a port.</p>

<p>My question is:</p>

<p>At the moment that i run the command:</p>

<pre><code>kubectl run tomcat-pod --image=tomcat --port=80 --labels="name=tomcat-pod"
</code></pre>

<p>In this moment the tomcat is running.</p>

<p>Then I believe that exposing like a service my tomcat with NodePort type, It will change my IP registration, because i have understanded that my server is registered with the command run?</p>

<p>Or what is the correct way to register my app with the Node machine using the tomcat in the container?</p>

<p>Thanks.</p>

<p>Regards.</p>

<p>To achieve your goal  and make <code>Tomcat</code> deployment available on the Node machine, consider using <code>Service</code> type <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">NodePort</a> to expose Tomcat application server on the <code>Node IP</code> address.</p>

<p>Create the manifest file for <code>Tomcat</code> application server implementation, ensuring that you remove previous Tomcat deployment:</p>

<pre><code>kubectl delete deployment tomcat-pod
</code></pre>

<p>Manifest file:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-pod
spec:
  selector:
    matchLabels:
      run: tomcat-pod
  replicas: 1
  template:
    metadata:
      labels:
        run: tomcat-pod
    spec:
      containers:
      - name: tomcat
        image: tomcat:latest
        ports:
        - containerPort: 8080
</code></pre>

<p>Create deployment for <code>Tomcat</code> in your K8s cluster:</p>

<pre><code>kubectl apply -f manifest_file.yaml
</code></pre>

<p>Compose service exposing your <code>Tomcat</code> container port (by default 8080):</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: tomcat-pod
  labels:
    run: tomcat-pod
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    run: tomcat-pod
</code></pre>

<p>Create service:</p>

<pre><code>kubectl apply -f manifest_file.yaml
</code></pre>

<p>Check your created service properties: <code>kubectl describe service tomcat-pod</code></p>

<pre><code>Name:                     tomcat-pod
Namespace:                default
Labels:                   run=tomcat-pod
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"run":"tomcat-pod"},"name":"tomcat-pod","namespace":"default"},"spec":{"port...
Selector:                 run=tomcat-pod
Type:                     NodePort
IP:                       XXX.XX.XX.XX
Port:                     &lt;unset&gt;  8080/TCP
TargetPort:               8080/TCP
NodePort:                 &lt;unset&gt;  30218/TCP
Endpoints:                XXX.XX.XX.XX:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>Now you can reach your Tomcat application server via Node IP address.</p>

<p>Be aware as <code>NodePort</code> is randomly selected from the default pool 30000-32767 and this value is unique for each Node in the cluster.</p>
