Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 4808abd

Browse files
YujiOshimaDavid Chung
authored andcommitted
Kubernetes flavor (#551)
Signed-off-by: YujiOshima <[email protected]>
1 parent a3b92e9 commit 4808abd

File tree

1,168 files changed

+473270
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,168 files changed

+473270
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ $(call define_binary_target,infrakit-group-default,github.com/docker/infrakit/cm
145145
$(call define_binary_target,infrakit-resource,github.com/docker/infrakit/cmd/resource)
146146
$(call define_binary_target,infrakit-flavor-combo,github.com/docker/infrakit/examples/flavor/combo)
147147
$(call define_binary_target,infrakit-flavor-swarm,github.com/docker/infrakit/examples/flavor/swarm)
148+
$(call define_binary_target,infrakit-flavor-kubernetes,github.com/docker/infrakit/examples/flavor/kubernetes)
148149
$(call define_binary_target,infrakit-flavor-vanilla,github.com/docker/infrakit/examples/flavor/vanilla)
149150
$(call define_binary_target,infrakit-flavor-zookeeper,github.com/docker/infrakit/examples/flavor/zookeeper)
150151
$(call define_binary_target,infrakit-instance-libvirt,github.com/docker/infrakit/cmd/instance/libvirt)
@@ -165,6 +166,7 @@ build-binaries: build/infrakit \
165166
build/infrakit-resource \
166167
build/infrakit-flavor-combo \
167168
build/infrakit-flavor-swarm \
169+
build/infrakit-flavor-kubernetes \
168170
build/infrakit-flavor-vanilla \
169171
build/infrakit-flavor-zookeeper \
170172
build/infrakit-instance-libvirt \

examples/flavor/kubernetes/README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
InfraKit Flavor Plugin - Kubernetes
2+
==============================
3+
4+
A [reference](/README.md#reference-implementations) implementation of a Flavor Plugin that creates a [Kubernetes](https://kubernetes.io/) cluster.
5+
6+
## Schema & Templates
7+
8+
This plugin has a schema that looks like this:
9+
10+
For manager
11+
```json
12+
{
13+
"InitScriptTemplateURL": "file:///home/ubuntu/go/src/github.com/docker/infrakit/examples/flavor/kubernetes/manager-init.sh",
14+
"KubeJoinIP": "192.168.2.200",
15+
"KubeBindPort": 6443,
16+
"KubeAddOns": [
17+
{
18+
"Name" : "flannel",
19+
"Type" : "network",
20+
"Path" : ""
21+
}
22+
]
23+
24+
}
25+
```
26+
For workers
27+
```json
28+
{
29+
"InitScriptTemplateURL": "file:///home/ubuntu/go/src/github.com/docker/infrakit/examples/flavor/kubernetes/worker-init.sh",
30+
"KubeJoinIP": "192.168.2.200",
31+
"KubeBindPort": 6443,
32+
}
33+
34+
```
35+
36+
Note `KubeJoinIP`, `KubeBindPort` that the Kubernetes connection information, as well as what IP in the Kubernetes managers and workers should use
37+
to advertise and join.
38+
39+
`KubeAddOns` is list of (kubernetes addons)[https://kubernetes.io/docs/concepts/cluster-administration/addons/].
40+
You can set Type as network or visualise.
41+
`network` Type addon should be set as your cluster will not be Ready status until network addon is applyed.
42+
43+
This plugin makes heavy use of Golang template to enable customization of instance behavior on startup. For example,
44+
the `InitScriptTemplateURL` field above is a URL where a init script template is served. The plugin will fetch this
45+
template from the URL and processe the template to render the final init script for the instance.
46+
47+
The plugin exposes a set of template functions that can be used, along with primitives already in [Golang template]
48+
(https://golang.org/pkg/text/template/) and functions from [Sprig](https://github.com/Masterminds/sprig#functions).
49+
This makes it possible to have complex templates for generating the user data / init script of the instances.
50+
51+
For example, this is a template for the init script of a manager node:
52+
53+
```
54+
#!/bin/sh
55+
set -o errexit
56+
set -o nounset
57+
set -o xtrace
58+
59+
{{/* Install Docker */}}
60+
{{ include "install-docker.sh" }}
61+
62+
{{/* Install Kubeadm */}}
63+
{{ include "install_kubeadam.sh" }}
64+
kubeadm init --token {{ KUBEADM_JOIN_TOKEN }}
65+
export KUBECONFIG=/etc/kubernetes/admin.conf
66+
{{ if NETWORK_ADDON }}
67+
kubectl apply -f {{ NETWORK_ADDON }}
68+
{{ else }}
69+
{{ end }}
70+
```
71+
72+
There are tags such as `{{ KUBEADM_JOIN_TOKEN }}` or `{{ INSTANCE_LOGICAL_ID }}`: these are made available by the
73+
plugin and they are evaluated / interpolated during the `Prepare` phase of the plugin. The plugin will substitute
74+
these 'placeholders' with actual values. The templating engine also supports inclusion of other templates / files, as
75+
seen in the `{{ include "install-docker.sh" }}` tag above. This makes it easy to embed actual shell scripts, and other
76+
texts, without painful and complicated escapes to meet the JSON syntax requirements. For example, the 'include' tag
77+
above will embed the `install-docker.sh` template/file:
78+
79+
```
80+
# Tested on Ubuntu/trusty
81+
82+
apt-get update -y
83+
wget -qO- https://get.docker.com/ | sh
84+
85+
```
86+
87+
### A Word on Security
88+
89+
Since Kubeadm use Token to authorize nodes, initializing
90+
the Kubernetes requires:
91+
92+
Docken socke API server exposes the remote API, but it is protected by TLS. Infrakit intends to make access to kubernetes manager from the side, but we can not send commands such as `get nodes` yet.
93+
For installation, we use [kubeadm](https://kubernetes.io/docs/admin/kubeadm/) and build a secure cluster.
94+
95+
96+
### Building & Running -- An Example
97+
98+
There are scripts in this directory to illustrate how to start up the InfraKit plugin ensemble and examples for creating a kubernetes via vagrant.
99+
100+
Building the binaries - do this from the top level project directory:
101+
```shell
102+
make binaries
103+
```
104+
105+
Start required plugins. We use the `infrakit plugin start` utility and a `plugins.json` to start up all the plugins,
106+
along with the InfraKit manager:
107+
108+
```shell
109+
infrakit-group-default
110+
infrakit-instance-vagrant
111+
infrakit-flavor-kubernetes
112+
```
113+
114+
Now start up the cluster comprised of a manager and a worker group. In this case, see `groups-master.json` where we will create a manager group of one node and in `group-worker.json` create a worker group of 3 nodes. The topology in this is a single ensemble of infrakit running on your local machine that manages 4 vagrant vms running Kubernetes.
115+
At Kubernetes flavor, you should run manager group first.
116+
Worker group will try to connect to manager before start.
117+
And as this flavor based on kubeadm, currently it support only one manager node.
118+
119+
```shell
120+
infrakit group commit groups-manager.json
121+
```
122+
Wait for manager comes up.
123+
As it need to install docker and kubeadm, it take a little time...
124+
125+
```shell
126+
infrakit group commit groups-worker.json
127+
```
128+
129+
Now cluster will come up.
130+
Now check the kubernetes:
131+
You should log in to manager node.
132+
Then
133+
134+
```shell
135+
export KUBECONFIG=/etc/kubernetes/admin.conf
136+
kubectl get nodes
137+
NAME STATUS AGE VERSION
138+
ip-192.168.2.200 Ready 4m v1.6.3
139+
ip-192.168.2.2 Ready 2m v1.6.3
140+
ip-192.168.2.3 Ready 2m v1.6.3
141+
ip-192.168.2.4 Ready 2m v1.6.3
142+
```

0 commit comments

Comments
 (0)