IP部署tomcat kubernetes [英] IP deployment tomcat kubernetes

查看:182
本文介绍了IP部署tomcat kubernetes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用我的Node IP和一个端口注册tomcat.

I need that tomcat is registered with my Node IP and a port.

我的问题是:

在我运行命令的那一刻:

At the moment that i run the command:

kubectl run tomcat-pod --image=tomcat --port=80 --labels="name=tomcat-pod"

此时,tomcat正在运行.

In this moment the tomcat is running.

然后,我相信像NodeM类型的tomcat一样公开我的tomcat,它将改变我的IP注册,因为我已经知道我的服务器是通过run命令注册的?

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?

或者使用容器中的tomcat在Node计算机上注册我的应用的正确方法是什么?

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

谢谢.

致谢.

推荐答案

要实现您的目标并使Tomcat部署在Node计算机上可用,请考虑使用Service键入

To achieve your goal and make Tomcat deployment available on the Node machine, consider using Service type NodePort to expose Tomcat application server on the Node IP address.

Tomcat应用程序服务器实现创建清单文件,确保删除先前的Tomcat部署:

Create the manifest file for Tomcat application server implementation, ensuring that you remove previous Tomcat deployment:

kubectl delete deployment tomcat-pod

清单文件:

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

在K8s集群中为Tomcat创建部署:

Create deployment for Tomcat in your K8s cluster:

kubectl apply -f manifest_file.yaml

组成服务公开您的Tomcat容器端口(默认为8080):

Compose service exposing your Tomcat container port (by default 8080):

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

创建服务:

kubectl apply -f manifest_file.yaml

检查您创建的服务属性:kubectl describe service tomcat-pod

Check your created service properties: kubectl describe service tomcat-pod

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:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30218/TCP
Endpoints:                XXX.XX.XX.XX:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

现在,您可以通过节点IP地址访问Tomcat应用程序服务器.

Now you can reach your Tomcat application server via Node IP address.

请注意,NodePort是从默认池30000-32767中随机选择的,并且该值对于集群中的每个节点都是唯一的.

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

这篇关于IP部署tomcat kubernetes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆