for-mac icon indicating copy to clipboard operation
for-mac copied to clipboard

Kubernetes is not exposing Node Ports to the host in Mac M1

Open quim3ra opened this issue 4 years ago • 4 comments

I have correctly setup my /etc/hosts in my mac m1:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1    localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

Working with docker desktop version 4.8.2 (79419) And having setup my k8s files as follows:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: posts-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: posts
  template:
    metadata:
      labels:
        app: posts
    spec:
      containers:
        - name: posts
          image: cbelizon/posts
apiVersion: v1
kind: Service
metadata:
  name: posts-srv
spec:
  type: NodePort
  selector:
   app: posts
  ports:
   - name: posts
     protocol: TCP
     port: 4000
     targetPort: 4000

When I run k logs posts-depl-647cb69856-pzjtk

[email protected] start
nodemon index.js

[nodemon] 2.0.16
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node index.js
v55
Listening on 4000

When I run k describe service posts-srv

Name:                     posts-srv
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=posts
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.99.64.231
IPs:                      10.99.64.231
LoadBalancer Ingress:     localhost
Port:                     posts  4000/TCP
TargetPort:               4000/TCP
NodePort:                 posts  32697/TCP
Endpoints:                10.1.0.34:4000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

`It is impossible to me to access http://localhost:32697/

The connection is refused, is there anything else that needs to be done to make docker desktop to make available the node ports to the host?

quim3ra avatar Jun 02 '22 14:06 quim3ra

I have a similar issue. It was working before the version 4.8.2. Starting with 4.8.2, it is not working anymore when I set a hostPort for a pod. It doesn't expose the port at the Docker level.

Docker Inspect:

"ExposedPorts": {
    "443/tcp": {},
    "80/tcp": {}
},

Pod:

ports:
- name: http
  hostPort: 80
  containerPort: 80
  protocol: TCP
- name: https
  hostPort: 443
  containerPort: 443
  protocol: TCP

m-ali-akbay avatar Jun 09 '22 20:06 m-ali-akbay

I am having the same issue, any update about this?

lunfardo avatar Aug 01 '22 16:08 lunfardo

Issues go stale after 90 days of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30 days of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle stale

docker-robott avatar Oct 30 '22 01:10 docker-robott

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

/lifecycle locked

docker-robott avatar Dec 29 '22 03:12 docker-robott