I'm new to Kubernetes and I'm learning. I have my Windows 8 machine where I installed Vagrant. Using vagrant I'm running ubuntu VM and inside that VM I'm running 3 docker containers.
Vagrant file:
Vagrant.configure(2) do |config|
config.vm.box = "test"
config.vm.network "public_network"
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 50000, host: 50000
config.vm.network "forwarded_port", guest: 8081, host: 8089
config.vm.network "forwarded_port", guest: 9000, host: 9000
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end
Container in Ubuntu VM :
root@vagrant-ubuntu-trusty:~/docker-containers# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dockercontainers_jenkins latest bb1142706601 4 days ago 1.03GB
dockercontainers_sonar latest 3f021a73750c 4 days ago 1.61GB
dockercontainers_nexus latest ddc31d7ad052 4 days ago 1.06GB
jenkins/jenkins lts 279f21046a63 4 days ago 813MB
openjdk 8 7c57090325cc 5 weeks ago 737MB
In same VM now I installed minikube and kubectl as mentioned in this link
minikube version:
minikube version: v0.24.1
kubectl version:
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.1", GitCommit:"3a1c9449a956b6026f075fa3134ff92f7d55f812", GitTreeState:"clean", BuildDate:"2018-01-04T11:52:23Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"0b9efaeb34a2fc51ff8e4d34ad9bc6375459c4a4", GitTreeState:"clean", BuildDate:"2017-11-29T22:43:34Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"linux/amd64"}
Minikube successfully started in my ubuntu VM. I have created pod.yml
file.
apiVersion: v1
kind: Pod
metadata:
name: testsonaralm
labels:
app: sonar_alm
spec:
containers:
- name: alm-sonar
image: dockercontainers_sonar:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9000
Using this yml file, I created a pod in minikube
root@vagrant-ubuntu-trusty:~/docker-containers# kubectl create -f test_pod.yml
pod "testsonaralm" created
Now I created a service using kubectl
command.
root@vagrant-ubuntu-trusty:~/docker-containers# kubectl expose pod testsonaralm --port=9000 --target-port=9000 --name almsonar
service "almsonar" exposed
root@vagrant-ubuntu-trusty:~/docker-containers# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
almsonar ClusterIP 10.102.86.193 <none> 9000/TCP 10s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d
When I tried to access the URL from my Host machine, I'm getting "Network Error".
root@vagrant-ubuntu-trusty:~/docker-containers# kubectl describe svc almsonar
Name: almsonar
Namespace: default
Labels: app=sonar_alm
Annotations: <none>
Selector: app=sonar_alm
Type: ClusterIP
IP: 10.101.237.223
Port: <unset> 9000/TCP
TargetPort: 9000/TCP
Endpoints: 172.17.0.1:9000
Session Affinity: None
Events: <none>
root@vagrant-ubuntu-trusty:~/docker-containers# minikube ip
127.0.0.1
When I execute the minikube service almsonar --url
command, I get an Empty response. So I deleted the service and created a new service with modified command.
root@vagrant-ubuntu-trusty:~/docker-containers# kubectl expose pod testsonaralm --type=NodePort --name almsonar
service "almsonar" exposed
Now when I run minikube service almsonar --url
command,I got an URL as
root@vagrant-ubuntu-trusty:~/docker-containers# minikube service almsonar --url
http://127.0.0.1:31209
root@vagrant-ubuntu-trusty:~/docker-containers# kubectl describe svc almsonar
Name: almsonar
Namespace: default
Labels: app=sonar_alm
Annotations: <none>
Selector: app=sonar_alm
Type: NodePort
IP: 10.101.192.1
Port: <unset> 9000/TCP
TargetPort: 9000/TCP
NodePort: <unset> 30600/TCP
Endpoints: 172.17.0.1:9000
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
root@vagrant-ubuntu-trusty:~/docker-containers# minikube ip
127.0.0.1
I'm unable to access this URL in my Ubuntu VM,
root@vagrant-ubuntu-trusty:~/docker-containers# curl http://127.0.0.1:31209
<HTML>
<HEAD><TITLE>Redirection</TITLE></HEAD>
<BODY><H1>Redirect</H1></BODY>
When I read the Kubernetes document, the minikube service URL will have a vaild IP. But in my case URL contains localhost IP address.
From what I see, you executed minikube start
inside the Ubuntu VM. By default, this would try to download the minikube ISO and launch another VM (VM inside a VM) where minikube would be running.
I think that this nested virtualization is causing issues with your installation. If, for some reason, minikube started with --vm-driver=none
to avoid the VM inside the VM (I think this is the case, looking at the 127.0.0.1 UP), there are some features that are in beta (by the time this answer was written), which could explain the weird behaviour. Because of this, my first advice would be to execute minikube inside the Windows host so it spins up a VM inside virtualbox. Inside you could reproduce the container environment you previously had, and execute the kubectl commands from the Windows host. Most of the documentation assume this setup, so you would not see differences like 127.0.0.1 in localhost.
In any case, in order to have full redirection and check if the service is running, try executing the curl command like this:
curl -L http://127.0.0.1:31209
You made a mistake when creating a pod or deployment using port number 80. That's why your URL service is not working, because 80 port is already busy. You need to use another port number, like 8080.
For Example:
$ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
$ kubectl expose pod hello-minikube --type=NodePort
$ minikube service hello-minikube --url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With