Cannot export a IP in minikube and haproxy loadBalancer - kubernetes

I'm newer with kubernetes. I've installed minikube v1.5.2 in a virtualbox VM (ubuntu 19.10). I want to create a web server that I can access from the host and guest. However, I can't access it or expose an IP. Could you help me?
I've already enabled the ingress addons.
When I try list the ingress object there is no external IP and I recive this error message from ingress controller deployment:
2019/11/10 15:41:04 controller-haproxy.go:147 service does not exists
2019/11/10 15:41:09 controller.go:333: service does not exists
2019/11/10 15:41:09 controller-haproxy.go:147 service does not exists
2019/11/10 15:41:14 controller.go:333: service does not exists
2019/11/10 15:41:14 controller-haproxy.go:147 service does not exists
This is my code: https://pastebin.com/ysMPtyuV

Minikube introduced supporting of LoadBalancer via minikube tunnel.
When you are not using $ sudo minikube tunnel your LB service will be in pending state whole time.
You need to open another SSH window and run $ sudo minikube tunnel. You will receive output in one SSH like:
$ sudo minikube tunnel
Status:
machine: minikube
pid: 11549
route: 10.96.0.0/12 -> 10.132.15.208
minikube: Running
services: [haproxy-ingress]
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
In the second SSH you will be able to check that LB service obtain IP address.
minikube:~$ kubectl get svc -w
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
app ClusterIP 10.105.136.11 <none> 80/TCP 68s
haproxy-ingress LoadBalancer 10.111.24.111 <pending> 80:31187/TCP 68s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11d
haproxy-ingress LoadBalancer 10.111.24.111 10.111.24.111 80:31187/TCP 80s
Please keep in mind that minikube tunnel session must be opened whole the time otherwise your LB will stop getting IP address.
You can check similar case with Kong using minikube LB.
Let me know if that helped you.

Related

ClusterIP not reachable within the Cluster

I'm struggling with kubernates configurations. What I want to get it's just to reach a deployment within the cluster. The cluster is on my dedicated server and I'm deploying it by using Kubeadm.
My nodes:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 9d v1.19.3
k8s-worker1 Ready <none> 9d v1.19.3
I've a deployment running (nginx basic example)
$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 29m
I've created a service
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9d
my-service ClusterIP 10.106.109.94 <none> 80/TCP 20m
The YAML file for my service is the following:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: nginx-deployment
ports:
- protocol: TCP
port: 80
Now I should expect, if I run curl 10.106.109.94:80 on my k8s-master to get the http answer.. but what I got is:
curl: (7) Failed to connect to 10.106.109.94 port 80: Connection refused
I've tried with NodePort as well and with targetPort and nodePort but the result is the same.
The cluster ip can not be reachable from outside of your cluster that means you will not get any response from the host machine that host your k8s cluster as this ip is not a part of your machine or any other machine rather than its a cluster ip which is used by your cluster CNI network like flunnel,weave.
So to get your services accessible from the outside or atleast from the host machine you have to change the type of your service like NodePort,LoadBalancer,K8s port-forward.
If you can change the service type NodePort then you will get response with any of your host machine ip and the allocated nodeport.
For example,if your k8s-master is 192.168.x.x and nodePort is 33303 then you can get response by
curl http://192.168.x.x:33303
or
curl http://worker_node_ip:33303
if your cluster is in locally installed, then you can install metalLB to get the privilege of load balancer.
You can also use port-forward to get your service accessible from the host that has kubectl client with k8s cluster access.
kubectl port-forward svc/my-service 80:80
kubectl -n namespace port-forward svc/service_name Port:Port

Cannot access Microk8s service from browser using NodePort service

I installed microk8s on my ubuntu machine based on steps here https://ubuntu.com/kubernetes/install#single-node
Then I followed kubernetes official tutorial and created and exposed a deployment like this
microk8s.kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
microk8s.kubectl expose deployment/kubernetes-bootcamp --type=NodePort --port 8083
This is my kubectl get services output
akila#ubuntu:~$ microk8s.kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 25h
kubernetes-bootcamp NodePort 10.152.183.11 <none> 8083:31695/TCP 17s
This is my kubectl get pods output
akila#ubuntu:~$ microk8s.kubectl get pods
NAME READY STATUS RESTARTS AGE
kubernetes-bootcamp-6f6656d949-rllgt 1/1 Running 0 51m
But I can't access the service from my browser using http://localhost:8083 OR using http://10.152.183.11:31695
When I tried http://localhost:31695 I'm getting ERR_CONNECTION_REFUSED.
How can I access this "kubernetes-bootcamp" service from my browser ?
Am I mising anything ?
The IP 10.152.183.11 is CLUSTER-IP and not accessible from outside the cluster i.e from a browser. You should be using http://localhost:31695 where 31695 is the NodePort opened on the host system.
The container of the gcr.io/google-samples/kubernetes-bootcamp:v1 image need to listen on port 8083 because you are exposing it on that port. Double check that because otherwise this will lead to ERR_CONNECTION_REFUSED error.
If the container is listening on port 8080 then use below command to expose that port
microk8s.kubectl expose deployment/kubernetes-bootcamp --type=NodePort --port 8080
Try this
kubectl port-forward <pod_name> <local_port>:<pod_port>
then access http://localhost:<local_port>

k8s: Get access to pods

I newbie question related with k8s. I've just installed a k3d cluster.
I've deployed an this helm chart:
$ helm install stable/docker-registry
It's been installed and pod is running correctly.
Nevertheless, I don't quite figure out how to get access to this just deployed service.
According to documentation, it's listening on 5000 port, and is using a ClusterIP. A service is also deployed.
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 42h
docker-registry-1580212517 ClusterIP 10.43.80.185 <none> 5000/TCP 19m
EDIT
I've been able to say to chard creates an ingress:
$ kubectl get ingresses.networking.k8s.io -n default
NAME HOSTS ADDRESS PORTS AGE
docker-registry-1580214408 chart-example.local 172.20.0.4 80 10m
Nevertheless, I'm still without being able tp push images to registry:
$ docker push 172.20.0.4/feedly:v1
The push refers to repository [172.20.0.4/feedly]
Get https://172.20.0.4/v2/: x509: certificate has expired or is not yet valid
Since the service type is ClusterIP, you can't access the service from host system. You can run below command to access the service from your host system.
kubectl port-forward --address 0.0.0.0 svc/docker-registry-1580212517 5000:5000 &
curl <host IP/name>:5000

external ip either goes pending or the assigned ip is not working

I deployed my service with the command kubectl expose deployment hotspot-deployment --type=LoadBalancer --port=8080
and the external-ip was pending:
hotspot-deployment LoadBalancer 10.104.104.81 <pending> 8080:31904/TCP 1m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 18m
After searching for it's solution, I assigned the external ip to my service with:
kubectl patch svc hotspot-deployment -p '{"spec": {"type": "LoadBalancer", "externalIPs":["192.168.98.103"]}}'
and the ip got assigned:
hotspot-deployment LoadBalancer 10.106.137.71 192.168.98.103 8080:31354/TCP 12m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 35m
Now, when I try to hit my service using the URL: http://192.168.98.103:8080
The page doesn't open. I tried debugging with
minikube tunnel
, it shows:
machine: minikube
pid: 33058
route: 10.96.0.0/12 -> 192.168.99.105
minikube: Running
services: [hotspot-deployment]
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
Please help!
First of all, you can not expose your service in minikube with LoadBalanser type because it intended to use cloud provider’s load balancer
You should rather use service command:
minikube service hotspot-deployment --url
Then open url in your browser

Kubernetes service stays in pending state

Service showing pending status after exposing the deployment.
packet#ubuntu:/home/gss$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 22h
wms1 LoadBalancer 10.106.19.103 <pending> 8000:32461/TCP 17h
Installed kubeadm with one master and 4 worker nodes.
created deployment with the command:
sudo docker run -p 8000:8000 w1
here w1 is my image name.
created service with the command:
kubectl expose deployment wms1 --type=LoadBalancer --port=8000
To retrieve external ip for your application in Kubernetes Cluster you have to use cloud provider like Google Kubernetes Engine or Amazon Web Services.
Please check:
https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#external-load-balancer-providers
Otherwise you can use Type NodePort and in that case Kubernetes master will allocate a port from a range specified by --service-node-port-range flag (default: 30000-32767), and each Node will proxy that port (the same port number on every Node) into your Service.
For detailed information: https://kubernetes.io/docs/concepts/services-networking/service/#nodeport
In a second terminal, run the command:
minikube tunnel
restart your service and you should see the EXTERNAL-IP populated