14,000 commits and 400 contributors (including one tiny commit from me!) is what build Kubernetes 1.0. It is now available!
- Download here
- API Docs
- Kubectl command tool
- Getting Started Guide
- Kubernetes Introduction Slides
This blog discusses some of the Kubernetes design patterns. All source code for the design patterns discussed below are available at kubernetes-java-sample.
Key Concepts of Kubernetes
At a very high level, there are three key concepts:
- Pods are the smallest deployable units that can be created, scheduled, and managed. Its a logical collection of containers that belong to an application.
- Master is the central control point that provides a unified view of the cluster. There is a single master node that control multiple minions.
- Node is a worker node that run tasks as delegated by the master. Minions can run one or more pods. It provides an application-specific “virtual host” in a containerized environment.
Some other concepts to be aware of:
- Replication Controller is a resource at Master that ensures that requested number of pods are running on nodes at all times.
- Service is an object on master that provides load balancing across a replicated group of pods.
- Label is an arbitrary key/value pair in a distributed watchable storage that the Replication Controller uses for service discovery.
Start Kubernetes Cluster
- Easiest way to start a Kubernetes cluster on a Mac OS is using Vagrant:
1234export KUBERNETES_PROVIDER=vagrantcurl -sS https://get.k8s.io | bash - Alternatively, Kubernetes can be downloaded from github.com/GoogleCloudPlatform/kubernetes/releases/download/v1.0.0/kubernetes.tar.gz, and cluster can be started as:
12345cd kubernetesexport KUBERNETES_PROVIDER=vagrantcluster/kube-up.sh
A Pod with One Container
This section will explain how to start a Pod with one Container. WildFly base Docker image will be used as the Container.
Pod, Replication Controller, Service, etc are all resources in Kubernetes. They can be created using the kubectl by using a configuration file.
The configuration file in this case:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
apiVersion: v1
kind: Pod
metadata:
name: wildfly-pod
labels:
name: wildfly
spec:
containers:
- image: jboss/wildfly
name: wildfly-pod
ports:
- containerPort: 8080
|
Complete details on how to create a Pod are explained at github.com/arun-gupta/kubernetes-java-sample#a-pod-with-one-container
Java EE Application Deployed in a Pod with One Container
This section will show how to deploy a Java EE application in a Pod with one Container. WildFly, with an in-memory H2 database, will be used as the container.
Configuration file is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
apiVersion: v1
kind: ReplicationController
metadata:
name: javaee7-hol
labels:
name: javaee7-hol
spec:
replicas: 1
selector:
name: javaee7-hol
template:
metadata:
labels:
name: javaee7-hol
spec:
containers:
- name: master
image: arungupta/javaee7-hol
ports:
- containerPort: 8080
hostPort: 8080
|
Complete details at github.com/arun-gupta/kubernetes-java-sample#java-ee-application-deployed-in-a-pod-with-one-container-wildfly–h2-in-memory-database.
A Replication Controller with Two Replicas of a Pod
This section will explain how to start a Replication Controller with two replicas of a Pod. Each Pod will have one WildFly container.
Configuration file is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
apiVersion: v1
kind: ReplicationController
metadata:
name: wildfly-rc
labels:
name: wildfly
context: docker-k8s-lab
spec:
replicas: 1
template:
metadata:
labels:
name: wildfly
spec:
containers:
- name: wildfly-rc-pod
image: arungupta/wildfly-mysql-javaee7:k8s
ports:
- containerPort: 8080
|
Complete details at github.com/arun-gupta/kubernetes-java-sample#a-replication-controller-with-two-replicas-of-a-pod-wildfly
Rescheduling Pods
Replication Controller ensures that specified number of pod “replicas” are running at any one time. If there are too many, the replication controller kills some pods. If there are too few, it starts more.
Complete details at github.com/arun-gupta/kubernetes-java-sample#rescheduling-pods.
Scaling Pods
Replication Controller allows dynamic scaling up and down of Pods.
Complete details at github.com/arun-gupta/kubernetes-java-sample#scaling-pods.
Kubernetes Service
Pods are ephemeral. IP address assigned to a Pod cannot be relied upon. Kubernetes, Replication Controller in particular, create and destroy Pods dynamically. A consumer Pod cannot rely upon the IP address of a producer Pod.
Kubernetes Service is an abstraction which defines a set of logical Pods. The set of Pods targeted by a Service are determined by labels associated with the Pods.
This section will show how to run a WildFly and MySQL containers in separate Pods. WildFly Pod will talk to the MySQL Pod using a Service.
Complete details at github.com/arun-gupta/kubernetes-java-sample#kubernetes-service.
Here are couple of blogs that will help you get started:
The complete set of Kubernetes blog entries provide more details.
Enjoy!
This is a great post. in particular, I like how you made the diagrams. I’ve been tracking jboss on kube for a while and its great to see the examples coming out !
PS The service load balances the requests, so you can have multiple MySQL shards that it points to for (i.e. for reads).
Excellent notes about the Kubernetes designs
Very interesting design solutions, thanks for sharing this article, I really love different articles on design, not so long ago I found a very interesting article https://uxplanet.org/top-user-experience-ui-ux-design-agencies-3696f3daed4e, read it if you also love design like me. Have a nice day!