0

Related:

Kubernetes service external ip pending

Kubernetes (Minikube) external ip does not work

Initial state:

$ kubectl.exe get service -o wide
NAME                    TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE   SELECTOR
kubernetes              ClusterIP      10.96.0.1        <none>        443/TCP          22h   <none>
mongo-express-service   LoadBalancer   10.102.123.226   <pending>     8081:30000/TCP   14m   app=mongo-express
mongodb-service         ClusterIP      10.104.217.138   <none>        27017/TCP        29m   app=mongodb

after patching with external IP:

$ kubectl patch svc mongo-express-service -p '{"spec": {"type": "LoadBalancer", "externalIPs":["172.31.71.218"]}}'
service/mongo-express-service patched

the service gets an external IP:

$ kubectl.exe get service -o wide
NAME                    TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)          AGE   SELECTOR
kubernetes              ClusterIP      10.96.0.1        <none>          443/TCP          22h   <none>
mongo-express-service   LoadBalancer   10.102.123.226   172.31.71.218   8081:30000/TCP   14m   app=mongo-express
mongodb-service         ClusterIP      10.104.217.138   <none>          27017/TCP        29m   app=mongodb

however it's not reachable:

$ wget 172.31.71.218:30000
--2022-05-05 00:23:11--  http://172.31.71.218:30000/
Connecting to 172.31.71.218:30000... failed: Connection timed out.
Retrying.

--2022-05-05 00:23:33--  (try: 2)  http://172.31.71.218:30000/
Connecting to 172.31.71.218:30000...

The service looks alright:

$ kubectl describe svc mongo-express-service
Name:                     mongo-express-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=mongo-express
Type:                     LoadBalancer
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.102.123.226
IPs:                      10.102.123.226
External IPs:             172.31.71.218
Port:                     <unset>  8081/TCP
TargetPort:               8081/TCP
NodePort:                 <unset>  30000/TCP
Endpoints:                172.17.0.4:8081
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason      Age   From                Message
  ----    ------      ----  ----                -------
  Normal  ExternalIP  34m   service-controller  Count: 0 -> 1

Launching the service with minikube:

$ minikube.exe service mongo-express-service
|-----------|-----------------------|-------------|---------------------------|
| NAMESPACE |         NAME          | TARGET PORT |            URL            |
|-----------|-----------------------|-------------|---------------------------|
| default   | mongo-express-service |        8081 | http://192.168.49.2:30000 |
|-----------|-----------------------|-------------|---------------------------|
* Starting tunnel for service mongo-express-service.
|-----------|-----------------------|-------------|-----------------------|
| NAMESPACE |         NAME          | TARGET PORT |          URL          |
|-----------|-----------------------|-------------|-----------------------|
| default   | mongo-express-service |             | http://127.0.0.1:1298 |
|-----------|-----------------------|-------------|-----------------------|
* Opening service default/mongo-express-service in default browser...
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
* Stopping tunnel for service mongo-express-service.

works for url http://127.0.0.1:1298 but not for the external ip.

minikube tunnel also fails:

$ minikube tunnel
* Tunnel successfully started

* NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ...

* Starting tunnel for service mongo-express-service.

When started, only the internal address is reachable:

enter image description here

It was reachable even before tunnel was started.

Setup: win 10, minikube started with docker image (minikube start --image=docker)

Is it possible to expose the internal address on windows?

mongo-express.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
      - name: mongo-express
        image: mongo-express
        ports:
        - containerPort: 8081
        env:
        - name: ME_CONFIG_MONGODB_ADMINUSERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-username
        - name: ME_CONFIG_MONGODB_ADMINPASSWORD
          valueFrom: 
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-password
        - name: ME_CONFIG_MONGODB_SERVER
          valueFrom: 
            configMapKeyRef:
              name: mongodb-configmap
              key: database_url
---
apiVersion: v1
kind: Service
metadata:
  name: mongo-express-service
spec:
  selector:
    app: mongo-express
  type: LoadBalancer  
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30000

mongo.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  labels:
    app: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - name: mongodb
        image: mongo
        ports:
        - containerPort: 27017
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-username
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom: 
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-password
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-service
spec:
  selector:
    app: mongodb
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017
Sebi
  • 4,262
  • 13
  • 60
  • 116
  • You manually specified the `externalIPs:` address. You can put literally any address you want there, but unless something actually creates a load balancer (minikube doesn't have a way to do this) it has no effect. – David Maze May 05 '22 at 16:14
  • @DavidMaze the service has been declared of type load balancer in the service (edited question). So, is there no way of using external addrs in minikube? – Sebi May 05 '22 at 19:18
  • See [Accessing apps](https://minikube.sigs.k8s.io/docs/handbook/accessing/) in the minikube documentation. Normally a Kubernetes controller sets that `externalIPs` field, and it is purely informative – it holds the address of the load balancer the controller has created, it doesn't tell the controller anything and it doesn't do anything if there isn't a corresponding controller. – David Maze May 05 '22 at 19:37
  • In other words there can be only one address (host-only) address that minikube can expose to the host machine, right? This address runs the service on a given port. If there are multiple services, each is assigned a different port, right? There's no way to connect to nodes directly as they don't have an external addr. Wanted to have a setup with a master and two workers and interact with them from the host machine (over a web service). – Sebi May 05 '22 at 20:15
  • If you're trying to do this on a single host, [kind](https://kind.sigs.k8s.io) may be easier to [set up](https://kind.sigs.k8s.io/docs/user/configuration/#nodes). Otherwise you'll probably need a "real" cluster installation; configuring that is a little beyond the programming-oriented scope of Stack Overflow. – David Maze May 06 '22 at 12:44
  • Alright! Not sure if that's doable on win but will try anyway – Sebi May 07 '22 at 18:37

1 Answers1

0

Looking at:

https://github.com/kubernetes/minikube/issues/7344#issuecomment-607318525

the docker network does not seem to work on win.

List of wins for which Hyper-V cannot be enabled:

Operating System Requirements
The Hyper-V role can be enabled on these versions of Windows 10:

Windows 10 Enterprise
Windows 10 Professional
Windows 10 Education
The Hyper-V role cannot be installed on:

Windows 10 Home
Windows 10 Mobile
Windows 10 Mobile Enterprise
List all of the features available in the operating system:

DISM /Online /Get-Feature

See what is the name listed there.

Download and install Windows 10 Client Hyper-V

Hyper-V on Windows 10 - Document links:

https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/windows_welcome

Requirements:

https://msdn.microsoft.com/virtualization/hyperv_on_windows/quick_start/walkthrough_compatibility

taken from:

https://social.technet.microsoft.com/Forums/ie/en-US/c3d8faaa-2e5a-4cfb-a681-9dfdf8bc5310/cant-install-hyperv-on-windows-10-version-1001024016384-feature-name-microsofthyperv-is?forum=win10itprovirt

Eventually had to use the docker vm. After reinstalling the latest version of virtual box and minicube, the existing host could not be loaded; already mentioned here:

https://github.com/kubernetes/minikube/issues/9130

win version:

systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List


OS Name             : Microsoft Windows 10 Home
OS Version          : 10.0.19044 N/A Build 19044
OS Manufacturer     : Microsoft Corporation
OS Configuration    : Standalone Workstation
OS Build Type       : Multiprocessor Free
System Boot Time    : 05/05/2022, 21:27:10
System Manufacturer : --
System Model        : --
System Type         : x64-based PC
System Directory    : C:\WINDOWS\system32
System Locale       : en-us;English (United States)
Hotfix(s)           : 13 Hotfix(s) Installed.,[01]: KB5012117,[02]: KB4562830,[03]: KB4577586,[04]: KB4580325,[05]:
                      KB4598481,[06]: KB5000736,[07]: KB5003791,[08]: KB5012599,[09]: KB5006753,[10]: KB5007273,[11]:
                      KB5011352,[12]: KB5011651,[13]: KB5005699
Sebi
  • 4,262
  • 13
  • 60
  • 116