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
Related
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>
I have executed minikube service mynginx1 and the result is:
|-----------|----------|-------------|-----------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------|-------------|-----------------------------|
| default | mynginx1 | 8080-80 | http://192.168.85.153:31706 |
|-----------|----------|-------------|-----------------------------|
What are the kubectl equivalent commands so that I can retrieve the URL if I am not using minikube?
To expose k8s application you can use kubectl expose
to create service of type NodePort:
kubectl expose pod <pod_name> --type NodePort --port 8080
or
kubectl expose deployment <deployment_name> --type NodePort --port 8080
then when you list your services you will see:
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
<service_name> NodePort 10.99.147.24 <none> 8080:31208/TCP 3s
Notice two ports under PORT column: 8080:31208/TCP. First is in-cluster port and the second is a node port. So now you can access your service with nodePort using: <node-IP>:31208 from outside of a cluster.
There is another option which only applies of you are running in cloud environment and LoadBalancers are supported (so if you are either using k8s as a service solution or running self hosted k8s in cloud with cloud provider configured).
You can create a service of type LoadBalancer like following:
kubectl expose pod <pod_name> --type LoadBalacer --port 8080
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
<service_name> LoadBalancer 10.107.151.19 x.x.x.x 8080:31111/TCP 2s
and now use EXTERNAL-IP address to connect to your service: x.x.x.x:8080
Port forward worked for me
kubectl port-forward deployment/es-manual 9200:9200
I had the same issue as the OP when trying to use Docker Desktop instead of Minikube - Docker desktop now comes with a Kubernetes single-node cluster so I didn't see the need to install Minikube in order to play with Kubernetes on my dev machine.
Assuming you use kubectl get services to list your services, you can then use kubectl cluster-info to get your master node ip.
OOTB, Docker Desktop sets 127.0.0.1 as the master node ip (or you could use kubernetes.docker.internal)
>> kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld NodePort 10.107.197.207 <none> 80:32714/TCP 71m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h4m
>> kubectl cluster-info
Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
With the above information I can launch helloworld at http://kubernetes.docker.internal:32714/ or http://127.0.0.1:32714/
equivalent to minikube service mynginx1
would be
kubectl get service mynginx1
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.
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
I'm following an example from Kubernetes in Action to run a simple docker image in kubernetes:
$ bx login --apikey #apiKey.json -a https://api.eu-de.bluemix.net
$ bx cs cluster-config my_kubernetes
$ export KUBECONFIG=..my_kubernetes.yml
Next, run the container:
$ kubectl run kubia --image=luksa/kubia --port=8080 --generator=run/v1
$ kubectl expose rc kubia --type=LoadBalancer --name kubia-http
$ kubectl get service
$ kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.10.10.1 <none> 443/TCP 20h
kubia-http 10.10.10.12 <pending> 8080:32373/TCP 0m
Fifteen minutes later ...
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.10.10.1 <none> 443/TCP 20h
kubia-http 10.10.10.12 <pending> 8080:32373/TCP 15m
I don't have anything else running on the Kubernetes cluster.
To close out the thread here, LoadBalancer cannot be used in a lite (aka free) cluster tier. The differences between lite and standard clusters can be found here - https://console.bluemix.net/docs/containers/cs_planning.html#cs_planning.
Run the following to determine if there are any failure events.
kubectl describe svc kubia-http
Thanks to Chris Rosen's answer, I was able to find a workaround:
$ bx cs workers my_kubernetes
OK
ID Public IP Private IP Machine Type State Status
kube-par01-xxxxx 1.2.3.4 6.7.8.9 free normal Ready
Note the Public IP address: 1.2.3.4
Expose the service with NodePort:
$ kubectl expose rc kubia --type=NodePort --name kubia-http2
Check the NodePort details:
$ kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.10.10.1 <none> 443/TCP 21h
kubia-http2 10.10.10.193 <nodes> 8080:31247/TCP 10s
Access the service using the exposed port on the worker Public IP address:
$ curl http://1.2.3.4:31247/
You've hit kubia-bjb59
Based on the posts above I was getting the following steps to work:
Prerequisites: Create a free Kubernetes cluster in the IBM Cloud and follow the steps (you need to have the ibmcloud and kubectl installed and connect to the remote cluster first)
kubectl get nodes
should return something like this
NAME STATUS ROLES AGE VERSION
10.76.197.55 Ready <none> 4h18m v1.18.10+IKS
Then,
kubectl apply -f https://k8s.io/examples/controllers/replication.yaml
replicationcontroller/nginx created
kubectl expose rc nginx --type=NodePort
service/nginx exposed
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 172.21.19.73 80:30634/TCP 70s
Note down the port, 30634 in my case
kubectl describe nodes |grep ExternalIP (to find out the external IP)
call IP:port
Have fun!
If your purpose is to test your application by having it the accessible to the external world , I would suggest using the NodePort service which can be used in the free tier service.
More Info can be found here : Expose service to world