Saturday, February 8, 2020

Cloud devops (part 2)


Kubernetes in 30 seconds

A container is an isolated application. For example, it may be Spark in what looks like its own OS.

A pod is the smallest unit of deployment and has one to many containers.

A replication controller maintains the requisite number of pods.

A service provides an API to external tools to manage the whole configuration, handles things like networking and lifetime management. "Headless-services allow us to reach each Pod directly, rather than the service acting as a load-balancer or proxy." [dev.to]

A namespace is a totally isolated logical area in which to run all of the above.

(This [YouTube] is a good 5 minute overview from VMWare that also talks about the kubelets - the primary “node agent” that runs on each node - and how they talk to the apiserver).


Google Kubernetes and Fabric8

Create a cluster in the "Kubernetes Engine" tab of your Google account. This can take about 5 minutes.

You will need to login:

$ gcloud auth login

and get the Google Kubernetes credentials:

$ gcloud container clusters get-credentials standard-cluster-1 --zone us-central1-a --project YOUR_PROJECT_NAME

Now, when you run:

$ kubectl config view

you'll see your Google config (as well as your MiniKube config if you've been using that already).

Now click on your Google Kubernetes cluster in the browser and find the 'Endpoint' value. Paste this into your Java code thus:

        String master = "https://YOUR_ENDPOINT:443/";
        if (args.length == 1) {
            master = args[0];
        }

        Config config = new ConfigBuilder().withMasterUrl(master).build();
        try (final KubernetesClient client = new DefaultKubernetesClient(config)) {
...

and you're good to go. I had Fabric8's FullExample running locally on my laptop creating and destroying pods in my Google hosted Kubernetes cluster.


Kubernetes cheats

Deleting a pod is not quite so straightforward as:

$ kubectl delete pods hello-minikube-797f975945-kntql
pod "hello-minikube-797f975945-kntql" deleted

(see this SO answer). If we've assigned replicas then a new pod may be started.

$ kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
hello-minikube-797f975945-rnqwc   1/1     Running   0          4m49s

Eh? Where did that come from?

You need to set the replicas to 0 with something like:

$ kubectl get all
NAME                                  READY   STATUS    RESTARTS   AGE
pod/hello-minikube-797f975945-rnqwc   1/1     Running   0          5m56s

NAME                     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
service/hello-minikube   NodePort    10.96.206.25           8080:32689/TCP   112m
service/kubernetes       ClusterIP   10.96.0.1              443/TCP          116m

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-minikube   1/1     1            1           112m

NAME                                        DESIRED   CURRENT   READY   AGE
replicaset.apps/hello-minikube-797f975945   1         1         1       112m
$ kubectl scale --replicas=0 deployment.apps/hello-minikube

(from this SO answer)

In production, it might be useful to login to running containers. You can do this with:

kubectl exec --stdin --tty shell-demo -- /bin/bash

(From the Kubernes docs)

No comments:

Post a Comment