Search code examples
kuberneteskubernetes-helmkubectlk3sk3sup

Kubernetes service is not reachable throw browser


I've deployed a small K3S cluster with a master and two workers:

The VMs were made with Multipass:

$ multipass ls
Name                    State             IPv4             Image
master-node             Running           10.200.68.230    Ubuntu 20.04 LTS
                                          10.42.0.0
                                          10.42.0.1
worker01                Running           10.200.68.67     Ubuntu 20.04 LTS
                                          10.42.1.0
                                          10.42.1.1
worker02                Running           10.200.68.227    Ubuntu 20.04 LTS
                                          10.42.2.0
                                          10.42.2.1

The cluster was made with k3sup:

$ kubectl get node
NAME          STATUS   ROLES                       AGE     VERSION
master-node   Ready    control-plane,etcd,master   13m     v1.21.3+k3s1
worker01      Ready    <none>                      10m     v1.21.3+k3s1
worker02      Ready    <none>                      9m46s   v1.21.3+k3s1

Workers are all labelled with ols.role=worker.

I'd like to install a NodeRed service on the workers nodes. I've used the following commands:

helm repo add k8s-at-home https://k8s-at-home.com/charts/
helm repo update
helm install node-red k8s-at-home/node-red --set nodeSelector."ols\.role"=worker
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=node-red,app.kubernetes.io/instance=node-red" -o jsonpath="{.items[0].metadata.name}")
while [[ $(kubectl get node $POD_NAME -o 'jsonpath={..status.conditions[?(@.type=="Running")].status}') != "True" ]]; do echo "waiting for pod" && sleep 1; done
kubectl port-forward $POD_NAME 8080:1880&

The service is supposed to be running on port 8080.

Pod's logs look ok:

$ kubectl logs $POD_NAME

> [email protected] start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"

29 Jul 08:20:12 - [info]

Welcome to Node-RED
===================

29 Jul 08:20:12 - [info] Node-RED version: v1.3.5
29 Jul 08:20:12 - [info] Node.js  version: v10.24.1
29 Jul 08:20:12 - [info] Linux 5.4.0-80-generic x64 LE
29 Jul 08:20:12 - [info] Loading palette nodes
29 Jul 08:20:12 - [info] Settings file  : /data/settings.js
29 Jul 08:20:12 - [info] Context store  : 'default' [module=memory]
29 Jul 08:20:12 - [info] User directory : /data
29 Jul 08:20:12 - [warn] Projects disabled : editorTheme.projects.enabled=false
29 Jul 08:20:12 - [info] Flows file     : /data/flows.json
29 Jul 08:20:12 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

29 Jul 08:20:12 - [info] Server now running at http://127.0.0.1:1880/
29 Jul 08:20:12 - [info] Starting flows
29 Jul 08:20:12 - [info] Started flows

When I try to reach the webpage (http://192.168.1.14:8080 or even http://127.0.0.1:1880/), the server responds an error: ERR_CONNECTION_REFUSED

The services should be running:

$ kubectl get services
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.43.0.1     <none>        443/TCP    32m
node-red     ClusterIP   10.43.18.33   <none>        1880/TCP   26m

Is there something else to do to make it work ?


Solution

  • Since your service is Cluster Ip you can not access the service out of Kubernetes cluster.

    You have to expose your service as Node port or Loadbalancer.

    https://kubernetes.io/docs/concepts/services-networking/service/

    however, for testing and debugging locally you can use this command :

    kubectl port-forward svc/node-red -n <replace-namespace-name> 1880:1880
    

    once command running open the browser and open URL

    HTTP://localhost:1880