Duration: 7:00
In Kubernetes every pod has a unique IP address! You can “login” into one of these pods by using the kubectl exec command. This can drop you into a shell and execute commands inside of the container.
First, find the name of the both helloworld-service-vertx pods:
[vagrant@rhel-cdk kubernetes]$ kubectl get pods -l app=helloworld-service-vertx
NAME READY STATUS RESTARTS AGE
helloworld-service-vertx-????? 1/1 Running 0 14m
helloworld-service-vertx-????? 1/1 Running 0 15m
Note
|
Note that we used the parameter -l app=helloworld-service-vertx. This parameter allows us to specify labels as filter. The label app=helloworld-service-vertx was defined in the ReplicationController as a template for all pods. |
Then, use kubectl exec to exucute a "bash" process into the container:
[vagrant@rhel-cdk kubernetes]$ kubectl exec -it helloworld-service-vertx-????? bash
[jboss@helloworld-service-vertx-????? ~]$ _
You are now in a shell inside of the helloworld-service-vertx container. You can run ps, and hostname:
[jboss@helloworld-service-vertx-edux9 ~]$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
jboss 1 0.2 1.7 2691876 51696 ? Ssl 20:24 0:02 java -Xmx256m -
jboss 22 0.1 0.0 11772 1832 ? Ss 20:40 0:00 bash
jboss 38 0.0 0.0 47424 1656 ? R+ 20:41 0:00 ps aux
[jboss@helloworld-service-vertx-edux9 ~]$ hostname -i
172.17.0.7
[jboss@helloworld-service-vertx-edux9 ~]$ exit
exit
Don’t forget to exit :).
Try it with another the other pod and see its IP address.
[vagrant@rhel-cdk kubernetes]$ kubectl exec -it helloworld-service-vertx-????? bash
[jboss@helloworld-service-vertx-????? ~]$ hostname
helloworld-service-vertx-?????
[jboss@helloworld-service-vertx-????? ~]$ hostname -i
172.17.0.8
[jboss@helloworld-service-vertx-????? ~]$ exit
Since we are running two instances of the Hello World Service (one instance in one pod), and that the IP addresses are not only unique, but also ephemeral - how will a client reach our services? We need a way to discover the service.
In Kubernetes, Service Discovery is a first class citizen. We created a Service that will:
-
act as a load balancer to load balance the requests to the pods, and
-
provide a stable IP address, allow discovery from the API, and also create a DNS name!
If you login into a container (find and use the frontend-ui container), you can access the helloworldservice via the DNS name:
[vagrant@rhel-cdk kubernetes]$ kubectl exec -it frontend-ui-????? bash
bash-4.2$* wget -qO- http://helloworld-service-vertx:8080/api/hello/Rafael*
Hello Rafael from helloworld-service-vertx-a4zq3 with 1.0
bash-4.2$ exit
exit
Pretty simple right!?