kompose未公开NodePort-桌面窗口的Docker

kompose未公开NodePort-桌面窗口的Docker,docker,kubernetes,docker-compose,kompose,Docker,Kubernetes,Docker Compose,Kompose,我有一个本地kubernetes集群(默认docker桌面上下文)运行的docker compose.yml和docker for Desktop Windows: docker compose up-d工作正常,并在127.0.0.1上的端口3000上公开我的节点 我正在尝试迁移我的k8s集群,因此 上面的页面说“如果你还没有运行Kubernetes集群,minikube是最好的开始方式”。。。我已经在为桌面集群运行OOTB Docker,所以我假设我不需要minikube kompose c

我有一个本地kubernetes集群(默认docker桌面上下文)运行的docker compose.yml和docker for Desktop Windows:

docker compose up-d
工作正常,并在
127.0.0.1
上的端口
3000
上公开我的节点

我正在尝试迁移我的k8s集群,因此

上面的页面说“如果你还没有运行Kubernetes集群,minikube是最好的开始方式”。。。我已经在为桌面集群运行OOTB Docker,所以我假设我不需要minikube

kompose convert
INFO Kubernetes file "datastore-service.yaml" created
INFO Kubernetes file "web-service.yaml" created
INFO Kubernetes file "datastore-deployment.yaml" created
INFO Kubernetes file "web-deployment.yaml" created
以下是web部署和web服务YAML:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.service.type: nodeport
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: web
  name: web
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: web
    spec:
      containers:
        image: customnode
        name: web
        ports:
        - containerPort: 3000
        resources: {}
      restartPolicy: Always
status: {}

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.service.type: nodeport
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: web
  name: web
spec:
  ports:
  - name: "3000"
    port: 3000
    targetPort: 3000
  selector:
    io.kompose.service: web
  type: NodePort
status:
  loadBalancer: {}

最后,运行
kompose up

kompose up
[36mINFO[0m We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.

INFO Deploying application in "default" namespace
INFO Successfully created Service: datastore
INFO Successfully created Service: web
INFO Successfully created Deployment: datastore
INFO Successfully created Deployment: web
kubectl get svc的输出

kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
datastore    ClusterIP   10.103.***.***   <none>        27017/TCP        76s
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP          23m
web          NodePort    10.106.***.***     <none>        3000:32033/TCP   76s
kubectl获取svc
名称类型CLUSTER-IP外部IP端口年龄
数据存储群集IP 10.103.*.**27017/TCP 76s
kubernetes ClusterIP 10.96.0.1 443/TCP 23m
web节点端口10.106.*.**3000:32033/TCP 76s

正如您所看到的,没有我所期望的外部IP。我确信这是我自己缺乏知识,而不是一个bug,那么我缺少什么呢?

extnal IP只分配给
负载平衡器
类型服务。群集上必须安装
负载平衡器
控制器,才能使
负载平衡器
服务正常工作。Else
LoadBalancer
服务的行为与
NodePort
服务完全相同。大多数云提供商都支持
LoadBalancer
服务

对于
NodePort
类型的服务,服务绑定到所有节点上节点端口范围内的随机端口。在您的示例中,您可以看到,服务绑定到端口32033-
3000:32033/TCP

节点端口范围配置为Kubernetes API server的参数,选项为
--服务节点端口范围
(默认情况下为30000-32767)。创建节点端口类型服务时,将从此范围中选择一个随机空闲端口。如果要选择自定义端口,可以在
端口
对象中指定
节点端口
属性

例如:

kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
datastore    ClusterIP   10.103.***.***   <none>        27017/TCP        76s
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP          23m
web          NodePort    10.106.***.***     <none>        3000:32033/TCP   76s
apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.service.type: nodeport
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: web
  name: web
spec:
  ports:
  - name: "3000"
    port: 3000
    targetPort: 3000
    nodePort: 30002         ###### You can choose node port here if needed
  selector:
    io.kompose.service: web
  type: NodePort           ####### Change this line to LoadBalancer if you want an external IP
status:
  loadBalancer: {}