I am learning kubernetes and using minikube to create single node cluster in my ubuntu machine. In my ubuntu machine Oracle Virtualbox is also installed. As I run
$ minikube start
Starting local Kubernetes v1.6.4 cluster...
...
$ cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority: /root/.minikube/ca.crt
server: https://192.168.99.100:8443
name: minikube
...
$ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8000
error: failed to discover supported resources: Get https://192.168.99.100:8443/api: Service Unavailable
I am not getting that what is causing this error. Is there some place we can check for logs. I cannot use kubectl logs as it requires container to mention which is not creating at all. Please provide any possible solution to problem.
You can debug using these steps:
kubectl talks to kube-apiserver at port 8443 to do its thing. Try curl -k https://192.168.99.100:8443 and see if there's a positive response. If this fails, it means kube-apiserver isn't running at all. You can try restarting the VM or rebuilding minikube to see if it comes up properly the 2nd time round.
You can also debug the VM directly if you feel brave. In this case, get a shell on the VM spun up by minikube. Run docker ps | grep apiserver to check if the kube-apiserver pod is running. Also try ps aux | grep apiserver to check if it's run natively. If both don't turn up results, check the logs using journalctl -xef.
Related
The setup:
I have a minikube setup and a docker-compose setup side by side running. This way I can easily develop my application within docker/docker-compose and run other services within minikube. I'm working on Linux (Ubuntu).
The problem:
I'd like to access the minikube API within a docker container running inside docker-compose with cURL.
What I've tried:
Accessing minikube with the proxy setup: curl http://localhost:8080/api (when using the kubectl proxy kubectl proxy --port=8080) but that ofcourse won't work because localhost is the container's localhost. This leads to curl: (7) Failed to connect to localhost port 8080: Connection refused
Accessing minikube via the docker internal host: curl http://host.docker.internal:8080/api. This also leads to curl: (7) Failed to connect to host.docker.internal port 8080: Connection refused.
Accessing minikube through the api/credentials found from the script below:
APISERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
SECRET_NAME=$(kubectl get secrets | grep ^default | cut -f1 -d ' ')
TOKEN=$(kubectl describe secret $SECRET_NAME | grep -E '^token' | cut -f2 -d':' | tr -d " ")
curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
But that all fails.
I've also added this to my docker-compose.yml file:
extra_hosts:
- "host.docker.internal:host-gateway"
It all works fine when I try the above commands outside the docker container.
How do I access minikube from inside a docker container?
Thanks in advance!
I strongly suggest that you wrap you development also using kubernetes manifests and deploy your service inside cluster. Just one time setup and then you can test multiple times instead of docker-compose way for dev setup.
Having said that, I tried your above setup (But I tried in mac, minikube and docker for mac). The solution that worked was doing exactly these:
Add extra_hosts to docker-compose:
version: "3.9"
services:
busy1:
image: progrium/busybox
command: sleep 3600
extra_hosts:
- "host.docker.internal:host-gateway"
Run a hello-world sample and expose it using service in minikube (this is similar to creating deployment and service manifests)
minikube kubectl -- create deployment node-hello --image=gcr.io/google-samples/node-hello:1.0 --port=8080
minikube kubectl -- expose deployment node-hello --port=8080
Run minikube with flag --disable-filter=true to overcome forbidden as response.
minikube kubectl -- proxy --disable-filter=true --port=8080
Use host.docker.internal from within the container running in docker to access host
curl http://host.docker.internal:8080/api/
{
"kind": "APIVersions",
"versions": [
"v1"
],
"serverAddressByClientCIDRs": [
{
"clientCIDR": "0.0.0.0/0",
"serverAddress": "192.168.49.2:8443"
}
]
}
So basically flow is, container -> host.docker.internal -> kubectl proxy -> kubernetes service -> kubectl deployment
It totally depends on your kubernetes service configuration so that proxy will work fine. But like I said before, develop with kubernetes first mode and so that you can focus in logic and business functionality than worrying about network complexity. And all these varies with docker version, platform (linux, mac, windows etc), service configuration (or ingress) etc, bridge or overlay or host network used. Good luck.
I am working on POC to setup IBM API Connect v2018 on IBM Kubernetes Service.
I setup my IBM Kubernetes cluster environments and kubectl commands working fine.
Below command output/results are showing as expected:
ibmcloud login -a cloud.ibm.com -r eu-de -g Default
kubectl config current-context
kubectl get services --namespace=kube-system
ibmcloud cs clusters
ibmcloud cs cluster config --cluster myclsuter
kubectl get nodes
kubectl get pods -n kube-system
The Problem occurs when I am trying to install Docker Registry.
Trying to install Docker registry in IBM Kubernetes Services error exception thrown as below:
ibmcloud cr login
FAILED
Could not locate 'docker'. Check your 'docker' installation and path.
When I type docker in IBM Cloud Shell:
-bash: docker: command not found
Can anyone please suggest how to install Docker on IBM Kubernetes Service...
I upgraded to docker stable version 2.0.0.3 running in my local. Earlier I had docker CE 17.06 which only had docker and kubernetes options were missing.
When I ran kubectl cluster-info dump I get the output in terminal.
How can I fix this? I have 3 docker containers fir which I wanted to run in Kubernetes now instead of using docker networks all alone. When running kubectl cluster-info this is the output-
Kubernetes master is running at https://localhost:6443
I am using the local Kubernetes cluster from Docker Desktop on Windows 10. No virtual machines, no minikubes.
I need to expose a port on my localhost for some service.
For example, I take kubernetes-bootcamp image from the official tutorial:
docker pull jocatalin/kubernetes-bootcamp:v2
Put it in the local registry:
docker tag jocatalin/kubernetes-bootcamp:v2 localhost:5000/kubernetes-bootcamp
docker push localhost:5000/kubernetes-bootcamp
Then create a deployment with this image:
kubectl create deployment kubernetes-bootcamp --image=localhost:5000/kubernetes-bootcamp
Then let's expose a port for accessing our deployment:
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl get services
kubernetes-bootcamp NodePort 10.102.167.98 <none> 8080:32645/TCP 8s
So we found out that the exposed port for our deployment is 32645. Let's try to request it:
curl localhost:32645
Failed to connect to localhost port 32645: Connection refused
And nothing is work.
But if I try port-forward everything is working:
kubectl port-forward deployment/kubernetes-bootcamp 7000:8080
Forwarding from 127.0.0.1:7000 -> 8080
Forwarding from [::1]:7000 -> 8080
Handling connection for 7000
Another console:
curl localhost:7000
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b5598d7b5-8qf9j | v=2
What am I doing wrong? I have found out several posts like mine, but none of them help me.
try to run the this CMD:
kubectl get svc | grep kubernetes-bootcamp
after this expose the pod to your network by using the CMD:
kubectl expose pod (podname) --type=NodePort
After that, you can check the URL by using the cmd example
minikube 0r kubectl service (service name) --url
So I have found out the problem root - local Kubernetes cluster somehow work the inappropriate way.
How I solve the problem:
Remove C:\ProgramData\DockerDesktop\pki
Recreate all pods, services, deployments
Now the same script I use before works great.
i am trying to deploy containers to local kubernetes, for now i have install docker deamon, minikube and minikube dashboard. this all are working fine. i had also setup local container repository on port 5000. i had also push 2 images of my application. i can see them on browser http://localhost:5000/v2/_catalog
now when i am trying to up pod using minikube.
kubectl apply -f ./docker-compose-k.yml --record
I am getting error on dashboard like this:-
Failed to pull image "localhost:5000/coremvc2": rpc error: code = Unknown desc = Error response from daemon: Get http://localhost:5000/v2/: dial tcp 127.0.0.1:5000: connect: connection refused
Here is my compose file:-
apiVersion: apps/v1
kind: Deployment
metadata:
name: core23
labels:
app: codemvc
spec:
replicas: 1
selector:
matchLabels:
app: coremvc
template:
metadata:
labels:
app: coremvc
spec:
containers:
- name: coremvc
image: localhost:5000/coremvc2
ports:
- containerPort: 80
imagePullPolicy: Always
i don't know why this images are not pulled as docker deamon and kubernetes both are on same machine. i have also try this with dockerhub image and it's working fine, but i want to do this using local images.
please give me hint or any guideline.
Thank you,
Based on the comment, you started minikube with minikube start (without specifying the driver).
That means that the minikube is running inside a Virtualbox VM. In order to make your use case work, you have two choices :
The hard way Set-up the connection between you VM and your host and use your host IP
The easy way Connect to your VM using minikube ssh and install your registry there. Then your deployment should work with your VM's IP.
If you don't want to use Virtual box, you should read the documentation about other existing drivers and how to use them.
Hope this helps !
The issue is that you have setup docker registry on your host machine and minikube runs in virtualized environment (according to your example it is Virtualbox).
That is why you are receiving "connection refused" error upon attempt to fetch image on port 5000. The root cause is that there is no process "inside" minikube that listens on 5000. Your registry is deployed "outside" of minikube.
As Marc told, there are 2 ways to fix ita and I have reproduced both. The Hard way will get you to:
Failed to pull image "10.150.0.4:5000/my-alpine": rpc error: code = Unknown desc = Error response from daemon: Get https://10.150.0.4:5000/v2/: http: server gave HTTP response to HTTPS client
So you'll have to set-up secure Docker registry according to The Docker Documentation
The easy way is to set it up on top of your minikube.
my#linux-vm2:~$ minikube ssh
$ docker run -d -p 5000:5000 --restart=always --name registry registry:2
...
Status: Downloaded newer image for registry:2
$ docker pull nginx:latest
...
Status: Downloaded newer image for nginx:latest
$ docker tag alpine:latest localhost:5000/my-nginx
$ docker push localhost:5000/my-nginx
$ logout
my#linux-vm2:~$ kubectl apply -f ./docker-compose-k.yml --record
deployment.apps/core23 created
my#linux-vm2:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
core23-b44b794cb-vmhwl 1/1 Running 0 4s
my #linux-vm2:~$ kubectl describe pods
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled <unknown> default-scheduler Successfully assigned default/core23-b44b794cb-vmhwl to minikube
Normal Pulling 9s kubelet, minikube Pulling image "localhost:5000/my-nginx"
Normal Pulled 9s kubelet, minikube Successfully pulled image "localhost:5000/my-nginx"
Normal Created 9s kubelet, minikube Created container coremvc
Normal Started 9s kubelet, minikube Started container coremvc
Please note that I've been using nginx instead of coremvc2 in this example (but still steps are the same).
To sum it up, it is possible to achieve the result you need in a few different ways. Please try and let us know how it went. Cheers :)
localhost:5000 is pointing to the pod itself.
If the Docker registry is running on the same host where minikube is running:
Get the IP address of the host (e.g. using ifconfig). Say, it is 10.0.2.15.
Tag the image:
docker tag coremvc2:latest 10.0.2.15:5000/coremvc2:latest
Push the so-tagged image to the local registry:
docker push 10.0.2.15:5000/coremvc2:latest
Change in the Deployment:
image: localhost:5000/coremvc2
to
image: 10.0.2.15:5000/coremvc2:latest
EDIT: If getting "...http: server gave HTTP response to HTTPS client" error, you could configure the local Docker registry as insecure registry for the local Docker daemon by editing /etc/docker/daemon.json (create it if it doesn’t exist):
{
... any other settings or remove this line ...
"insecure-registries": ["10.0.2.15:5000"]
}
...then restart docker:
sudo service docker restart
Not sure how you run the local Docker registry, but this is one way:
docker run -d -p 5000:5000 --name registry registry:2