Wednesday, November 9, 2016

We continue reading on Kubernetes. Kubernetes is not a traditional, all-inclusive PaaS. Unlike PaaS that restricts applications, dictates choice of application frameworks, restrict supported language runtimes or distinguish apps from services, Kubernetes aims to support an extremely diverse variety of workloads. As long as the application has been compiled to run in a container, it will work with Kubernetes. PaaS provides databases, message bus, cluster storage systems but those can run on Kubernetes. There is also no click to deploy service marketplace. Kubernetes does not build user code or deploy it. However it facilitates CI workflows to run on it.
Kubernetes allows users to choose logging, monitoring and alerting Kubernetes also does not require a comprehensive application language or system. It is independent of machine configuration or management. But PaaS can run on Kubernetes and extend its reach to different clouds.
A Kubernetes cluster can be launched on machines running Ubuntu 16.04, CentOS 7 or HypriotOS v1.0.1+ with an installation tool called kubeadm. The process works with local VMs, physical servers and/or cloud servers. This tool assumes we have a set of machines virtual or real but is preferable over baremetal. Each machine should have 1 GB RAM and there should be full network connectivity between all machines in the cluster.
Kubernetes cluster can be installed on cloud. While this was preferable over AWS, we now have Azure supporting Kubernetes installation. This is done with a tool called kops and is well-known for its high availability support. It is self healing, auto-scaling and can directly provision or generate terraform manifests. It uses fully qualified name for addressing within the cluster and outside. It creates a route53 domain for the cluster so all the cluster machines can be looked up without remembering each one's ipaddress or name. It creates an s3 bucket to store the cluster state. It builds the cluster configuration. It creates the cluster in AWS and enables several add-ons such as WeaveNet, Calico, Flannel, Canal and Romana for networking, WeaveScope and Dashboard for web interface and Legacy Add-ons.
#codingexercise
Find a tour for a trucker to visit all gas stations in a circle
The naiive solution can be O(n^2) but we can make it linear.
int Tour(List<int>fill, List<int>use)
{
int min = int_max;
int reserve = 0;
int index = 0;
for (int i =0; i < fill.size; i++)
{
    reserve += fill[i] - use[i];
    if (reserve < min)
    {
        min = reserve;
        index = (i+1) % fill.size;
     }
}
if (reserve >= 0)
     return index;
return -1;
}
Convert a binary tree into one where the nodes have the sum of left and right subtree
int ToSumTree(node root)
{
if (root == null) return 0;
int val = root.data;
root.data = ToSumTree(root.left) + ToSumTree(root.right);
return root.data + val;
}
The same algorithm remains true even if we wanted the difference instead of sum.

Given a sequence of words, print all anagrams together.

Void PrintAllAnagrams(List<string> words)
{
Var items = new List<Tuple<string, int>>();
Words.enumerate((x,i) => items.Add(new Tuple<string, int>(x, i)));
Items.forEach(x => sort(x));
Items.sort(new TupleSorter());
Items.ForEach(x => console.writeLine("{0} at index {1}", words[x.second], words[x.second]);

}
Or we could simply cluster them based on anagram similarity 

No comments:

Post a Comment