Basic Exercises(Command line):

Below exercise, we use CLI to create the containers. The best option is YAML file, which we can see in the next section.

We just launch the docker image available in dockerhub (sureshkvl/test - which we build as part of Docker build section). This image is a RestAPIserver runs port 5000.

Run the docker image(sureshkvl/test) in minikube:

kubectrl run <deployment name> --image=<image name with repository and tag> --port=<exposing port>

cloud@mkube:~$ kubectl run smsapp --image=sureshkvl/test:1-2 --port=5000                                                       
deployment "smsapp" created
cloud@mkube:~$

Check the deployments:

cloud@mkube:~$ kubectl get deployments
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
smsapp    1         1         1            0           33s
cloud@mkube:~$

Check the Pods

cloud@mkube:~$ kubectl get pods
NAME                      READY     STATUS              RESTARTS   AGE
smsapp-1401646005-7bxmc   0/1       ContainerCreating   0          1m
cloud@mkube:~$ kubectl get pods
NAME                      READY     STATUS              RESTARTS   AGE
smsapp-1401646005-7bxmc   0/1       ContainerCreating   0          1m
cloud@mkube:~$ kubectl get pods
NAME                      READY     STATUS    RESTARTS   AGE
smsapp-1401646005-7bxmc   1/1       Running   0          7m
cloud@mkube:~$

Note: we have to wait till it moves to Running State.

Check the logs of the Pod.

cloud@mkube:~$ kubectl logs smsapp-1401646005-7bxmc
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 108-843-337
cloud@mkube:~$

Execute the commands in the Pod in interactive mode :

cloud@mkube:~$ kubectl exec -it smsapp-1401646005-88tn8 bash
root@smsapp-1401646005-88tn8:/app# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 05:59 ?        00:00:01 python sms.py
root         7     1  2 05:59 ?        00:00:42 /usr/bin/python sms.py
root        25     0  0 06:25 ?        00:00:00 bash
root        46     0  4 06:26 ?        00:00:00 bash
root        59    46  0 06:26 ?        00:00:00 ps -ef
root@smsapp-1401646005-88tn8:/app# exit
exit
cloud@mkube:~$

Execute the commands in pod

cloud@mkube:~$ kubectl exec smsapp-1401646005-88tn8 ps
  PID TTY          TIME CMD
    1 ?        00:00:01 python
    7 ?        00:00:46 python
   25 ?        00:00:00 bash
   60 ?        00:00:00 ps
cloud@mkube:~$

Expose the Port in outside:

create a service:

cloud@mkube:~$ kubectl expose deployment/smsapp --type="NodePort" --port 5000
service "smsapp" exposed
cloud@mkube:~$

To identify the exposed port,

cloud@mkube:~$ kubectl get services                                                                                        
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP          22h
smsapp       NodePort    10.0.0.138   <none>        5000:31316/TCP   1m
cloud@mkube:~$

we can see, new smsapp service and exposed port is 31316.

Curl request to the node (in our case only one node)

cloud@mkube:~$ curl 192.168.42.19:31316/students
{}
cloud@mkube:~$

Ref:

https://kubernetes.io/docs/user-guide/docker-cli-to-kubectl/

results matching ""

    No results matching ""