I am running Kubernetes locally by minikube on docker desktop macOS. I want to access the service Kubernetes by external IP. My problem also has a few similar topic on Stackoverflow but it's from 1, or 2 years before, I do according answer in that topic but was not successful so I create a new topic with full information about my case current.
kubectl version:
Client Version: v1.29.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.3
minikube version
minikube version: v1.32.0
docker version
Client:
Cloud integration: v1.0.35+desktop.5
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:04:20 2023
OS/Arch: darwin/arm64
Context: desktop-linux
Server: Docker Desktop 4.26.1 (131620)
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.20.10
Git commit: 311b9ff
Built: Thu Oct 26 09:08:15 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.25
GitCommit: d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
file manifest of service, use service type NodePort, Pod and Service are still running
kind: Service
apiVersion: v1
metadata:
name: web-service
namespace: default
uid: c5e8ffa5-ac4a-4db0-a692-a1e92c048280
resourceVersion: '12791'
creationTimestamp: '2024-01-02T18:51:05Z'
labels:
app: nginx
managedFields:
# ignore data
spec:
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 31856
selector:
app: nginx
clusterIP: 10.111.115.68
clusterIPs:
- 10.111.115.68
type: NodePort
sessionAffinity: None
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
status:
loadBalancer: {}
In terminal I run minikube ip to get external ip is 192.168.49.2, then run curl 192.168.49.2:31856, it is timeout don't return response
I try to stand in minikube node minikube ssh and try again curl 192.168.49.2:31856 it returns a response success.
I think maybe there was a mistake about the docker desktop's network but can't find to fix
I continue to use port-forward by command kubectl port-forward --address 0.0.0.0 service/web-service 80:80 to forward by port service 80
run curl localhost:80, it has the response success same when ssh into minikube

I think have a config to can connect ip of minikube node from outside but I still not to find right. Please help me if you have any ideal to do.
Thanks!


if you're using minikube then i would recommend to use the minikube tunnel command to access your services.
you can read more from here