Kubernetes from the kubectl Command Line

Oracle Container Engine (OCE)

You most likely read the news that Oracle joined the CNCF and now offers a Kubernetes service named Oracle Container Engine. Basically you could use OCE nicely integrated with the CI/CD Wercker or alternatively from the command line.

OCE with Wercker

About using Kubernetes together with Wercker I will present at the CODE conference in NY city. So stay tuned for slides and possibly a recording.

OCE with standard kubectl CLI

OCE is a standard upstream Kubernetes. So with an existing kubectl client that is correctly pointing to your OCE instance you can try your first K8s steps from the CLI. So here is a quick primer.

The first thing to note is that you should set your namespace if you are using the OCE trial. The reason is, that there is shared cluster for trial and different users are assigned different namespaces. Don’t worry, if you are following the example with Wercker, given to the trial participants the namespace will be set correctly.

Set your namespace, replace fmunz with your namespace in the command below:

$ kubectl config set-context $(kubectl config current-context) --namespace=fmunz

Create a pod and scale it to 3 and :

$ kubectl run microg --image=fmunz/microg --port 5555
$ kubectl scale --replicas=3 deployment/microg

Note, that so far you only have a pod running, but no service. So your container will not be reachable from the outside. Now expose it as a service via the NodePort:

$ kubectl expose deployment microg --type=NodePort

Maybe most difficult question is how to access the service. You can find the NODE IPs of the pods using the wide flag when retrieving information about the pods:

$ kubectl get pods -o wide

NAME                                  READY     STATUS    RESTARTS   AGE       IP              NODE
microg-858154966-bfhg9                1/1       Running   0          2h        10.244.56.146   129.213.30.58
microg-858154966-k4v07                1/1       Running   0          2h        10.244.93.146   129.213.58.116
microg-858154966-p1tn9                1/1       Running   0          2h        10.244.99.40    129.213.36.50

Pick one of the NODE IPs, e.g. 129.213.30.58. Next, retrieve the NodePort that was created.

$ kubectl describe service microg | grep NodePort
Type:                     NodePort
NodePort:                 <unset>  32279/TCP

Now you can simply combine port and IP for the URL to access the service:

$ curl -s 129.213.30.58:32279

Which will show the following service response:

{"date":"Tuesday, 27-Feb-18 15:12:47 UTC","ip":"10.244.99.40","rel":"v1.0","cnt":174}

Hit it a couple more more times to investigate the load balancing.