Minikube:从Docker容器公开RESTAPI

Minikube:从Docker容器公开RESTAPI,docker,rest,kubernetes,kubectl,minikube,Docker,Rest,Kubernetes,Kubectl,Minikube,我目前有一个停靠的Spring Boot应用程序,它带有公开的Java REST API,我将其部署到我的NUC(只是一台远程机器)上,并可以通过NUCs静态IP地址从我的Mac连接到它。两台机器位于同一网络上 我现在正在考虑在Kubernetes(Minikube)中托管Docker应用程序 (使用本教程) 我使用Kubernetes的Kompose工具将Docker compose文件转换为Kubernetes部署和服务文件。我首先要做的一个服务就是打开8080端口,并拥有大量的REST资源

我目前有一个停靠的Spring Boot应用程序,它带有公开的Java REST API,我将其部署到我的NUC(只是一台远程机器)上,并可以通过NUCs静态IP地址从我的Mac连接到它。两台机器位于同一网络上

我现在正在考虑在Kubernetes(Minikube)中托管Docker应用程序
(使用本教程)

我使用Kubernetes的Kompose工具将Docker compose文件转换为Kubernetes部署和服务文件。我首先要做的一个服务就是打开8080端口,并拥有大量的REST资源。一切似乎都已启动并运行,但我无法使用
curl-v
命令从Mac(甚至是NUC本身)访问其余资源

在解决了Docker映像的一个小问题(需要根据Minikube的内部Docker映像repo构建)后,我可以成功部署我的服务和部署。还有许多其他步骤,但为了完成这一步骤,我只介绍以下一个步骤:

$ kubectl get po -A

NAMESPACE         NAME                                 READY   STATUS    RESTARTS   AGE
kube-system       coredns-f9fd979d6-hhgn8              1/1     Running   0          7h
kube-system       etcd-minikube                        1/1     Running   0          7h
kube-system       kube-apiserver-minikube              1/1     Running   0          7h
kube-system       kube-controller-manager-minikube     1/1     Running   0          7h
kube-system       kube-proxy-rszpv                     1/1     Running   0          7h
kube-system       kube-scheduler-minikube              1/1     Running   0          7h
kube-system       storage-provisioner                  1/1     Running   0          7h
meanwhileinhell   apigw                                1/1     Running   0          6h54m
meanwhileinhell   apigw-75bc5z1f5j-cklxt               1/1     Running   0          6h54m
但是,我无法使用NUC的静态IP访问此主IP地址或任何预期的开放端口。我曾尝试对服务使用服务类型
LoadBalancer
NodePort
,但对于外部IP,前者挂起
pending

我已经尝试了一些暴露端口和端口转发,但是没有任何工作(端口7000只是一个任意数字):

这是我的
apigw
部署、服务和pod yaml文件:

apigw-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: apigw
  name: apigw
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: apigw
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.network/networkinhell: "true"
        io.kompose.service: apigw
    spec:
      containers:
          image: meanwhileinhell/api-gw:latest
          name: apigw
          ports:
            - containerPort: 8080
          resources: {}
          imagePullPolicy: Never
          volumeMounts:
            - mountPath: /var/log/gateway
              name: combined-logs
      hostname: apigw
      restartPolicy: Always
      volumes:
        - name: combined-logs
          persistentVolumeClaim:
            claimName: combined-logs
status: {}
apigw-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: apigw
  labels:
    run: apigw
spec:
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: apigw
  type: NodePort
apigw-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: apigw
  name: apigw
spec:
  containers:
    - image: meanwhileinhell/api-gw:latest
      name: apigw
      imagePullPolicy: Never
      resources: {}
      ports:
        - containerPort: 8080
使用
kubectl create-f
创建服务

Ubuntu 18.04.5 LTS
Minikube v1.15.0
KubeCtl v1.19.4

你在用什么minikube——驱动程序?嗨,Matt,我在用Linux Docker驱动程序
minikube配置集驱动程序Docker
你在Mac上运行kubectl吗?还是远程主机?我正在从远程主机运行它。请尝试
kubectl端口转发apigw 7000:8080--地址0.0.0
apiVersion: v1
kind: Service
metadata:
  name: apigw
  labels:
    run: apigw
spec:
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: apigw
  type: NodePort
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: apigw
  name: apigw
spec:
  containers:
    - image: meanwhileinhell/api-gw:latest
      name: apigw
      imagePullPolicy: Never
      resources: {}
      ports:
        - containerPort: 8080
Ubuntu 18.04.5 LTS
Minikube v1.15.0
KubeCtl v1.19.4