英文:
Cannot connect to KB external service using NodePort
问题
I cannot seem to find why couldn't connect to an endpoint I have exposed via NodePort. While the container is running as expected when running kubectl logs <pod>
, I am unable to reach:
http://<node ip>:30100/<valid endpoint form container>
where the <node ip>
is the ip from running kubectl get nodes -o wide
under INTERNAL IP
.
I am unsure whether the problem resides in the deployment yaml. Below is my single deployment that I've applied to the cluster:
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-app-deployment
labels:
app: auth-app
spec:
replicas: 1
selector:
matchLabels:
app: auth-app
template:
metadata:
labels:
app: auth-app
spec:
containers:
- name: auth-app
image: <working image>
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: auth-app-service
spec:
type: NodePort
selector:
app: auth-app
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30100
Also, here are the results from running kubectl get all
:
NAME READY STATUS RESTARTS AGE
pod/auth-app-deployment-58cd68d8cf-mjpph 1/1 Running 0 29m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/auth-app-service NodePort 10.104.172.176 <none> 80:30100/TCP 138m
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 150m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/auth-app-deployment 1/1 1 1 138m
NAME DESIRED CURRENT READY AGE
replicaset.apps/auth-app-deployment-58cd68d8cf 1 1 1 29m
PS: I am using minikube
.
英文:
I cannot seem to find why couldn't connect to an endpoint I have exposed via NodePort. While the container is running as expected when running kubectl logs <pod>
, I am unable to reach:
http://<node ip>:30100/<valid endpoint form container>
where the <node ip>
is the ip from running kubectl get nodes -o wide
under INTERNAL IP
.
I am unsure whether the problem resides in the deployment yaml. Below is my single deployment that I've applied to the cluster:
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-app-deployment
labels:
app: auth-app
spec:
replicas: 1
selector:
matchLabels:
app: auth-app
template:
metadata:
labels:
app: auth-app
spec:
containers:
- name: auth-app
image: <working image>
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: auth-app-service
spec:
type: NodePort
selector:
app: auth-app
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30100
Also, here are the results from running kubectl get all
:
NAME READY STATUS RESTARTS AGE
pod/auth-app-deployment-58cd68d8cf-mjpph 1/1 Running 0 29m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/auth-app-service NodePort 10.104.172.176 <none> 80:30100/TCP 138m
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 150m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/auth-app-deployment 1/1 1 1 138m
NAME DESIRED CURRENT READY AGE
replicaset.apps/auth-app-deployment-58cd68d8cf 1 1 1 29m
PS: I am using minikube
.
答案1
得分: 1
由于您正在使用 NodePort 服务,您不能使用集群 IP,它与节点 IP 不同。
假设您只有一个节点(因为您正在使用 minikube),您需要使用从 kubectl describe nodes
命令中获取的地址部分下的 IP,使用 InternalIP 值。
您的 URL 将是 http://<node_ip>:30100/<容器中有效的端点>
。
英文:
As you are using a NodePort service you can't use the cluster IP, which is different from the node IP's.
Assuming you only one have 1 node (bc you are using minikube) you need to use the ip you get from kubectl describe nodes
under the addresses section, use InternalIP value.
Your url will be http://<node_ip>:30100/<valid endpoint form container>
答案2
得分: 0
如果有人遇到与minikube相同的问题,您可以使用以下命令解决:minikube service <service>
,这会将服务暴露到localhost,类似于kubectl中的端口转发命令。
在我的情况下,命令如下:
minikube service auth-app-service
英文:
If anyone is coming across the same issue with minikube, you can use the I fixed the by using minikube service <service>
command which exposes the service to localhost, much like the port forward command in kubectl.
In my case, the command looks like this:
minikube service auth-app-service
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论