Skip to content

Commit 9bd09c3

Browse files
kinder
1 parent 72914ba commit 9bd09c3

Some content is hidden

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

45 files changed

+5168
-209
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# OSX trash
2+
.DS_Store
3+
4+
# Eclipse files
5+
.classpath
6+
.project
7+
.settings/**
8+
9+
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
10+
.idea/
11+
*.iml
12+
13+
# Vscode files
14+
.vscode

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module k8s.io/kubeadm
2+
3+
go 1.12

kinder/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# tmp folder for testing node variants
2+
/tmp

kinder/OWNERS

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See the OWNERS file documentation:
2+
# https://github.com/kubernetes/community/blob/master/contributors/devel/owners.md
3+
approvers:
4+
- fabriziopandini
5+
- neolit123
6+
reviewers:
7+
labels:
8+
- area/kubeadm
9+
- sig/cluster-lifecycle

kinder/README.md

+12-203
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kinder is an example of [kind](https://github.com/kubernetes-sigs/kind) used as
55
All the kind commands will be available in kinder, side by side with additional commands
66
designed for helping kubeadm contributors.
77

8-
**kinder is a work in progress. Test it! Break it! Send feeback!**
8+
**kinder is a work in progress. Test it! Break it! Send feedback!**
99

1010
## Prerequisites
1111

@@ -21,7 +21,7 @@ git --version
2121

2222
### Install Go
2323

24-
To work on kind’s codebase you will need [Go](https://golang.org/doc/install).
24+
To work with kinder you will need [Go](https://golang.org/doc/install).
2525

2626
Install or upgrade [Go using the instructions for your operating system](https://golang.org/doc/install).
2727
You can check if Go is in your system with the following command:
@@ -35,10 +35,7 @@ in lower versions.
3535

3636
## Getting started
3737

38-
Read the [kind documentation](https://kind.sigs.k8s.io/docs/user/quick-start/) first, becuase kinder
39-
is built using kind as a library.
40-
41-
Clone the kubeadm repo:
38+
Clone the kubeadm repository:
4239

4340
```bash
4441
git clone https://github.com/kubernetes/kubeadm.git
@@ -53,205 +50,17 @@ GO111MODULE=on go install
5350

5451
This will put kinder in $(go env GOPATH)/bin.
5552

56-
## Create a test cluster
57-
58-
You can create a cluster in kinder using `kinder create cluster`, that is a wrapper on the `kind create cluster` command.
59-
60-
However, additional flags are implemented for enabling following use cases:
61-
62-
### Create *only* nodes
63-
64-
By default kinder stops the cluster creation process before executing `kubeadm init` and `kubeadm join`;
65-
This will give you nodes ready for intalling Kubernetes and more specifically
66-
67-
- the necessary prerequisited already installed on all nodes
68-
- a pre-build kubeadm config file in `/kind/kubeadm.conf`
69-
- in case of more than one control-plane node exists in the cluster, a pre-configured external load balancer
70-
71-
If instead you want to revert to the default kind behaviour, you can use the `--setup-kubernetes`:
72-
73-
```bash
74-
kinder create cluster --setup-kubernetes=true
75-
```
76-
77-
### Testing different cluster topologies
78-
79-
You can use the `--control-plane-nodes <num>` flag and/or the `--worker-nodes <num>` flag
80-
as a shurtcut for creating different cluster topologies. e.g.
81-
82-
```bash
83-
# create a cluster with two worker nodes
84-
kinder create cluster --worker-nodes=2
85-
86-
# create a cluster with two control-pane nodes
87-
kinder create cluster ---control-plane-nodes=2
88-
```
89-
90-
Please note that a load balancer node will be automatically create when there are more than
91-
one control-plane node; if necessary, you can use `--external-load balancer` flag to explicitly
92-
request the creation of an external load balancer node.
93-
94-
More sophisticated cluster topologies can be achieved using the kind config file, like e.g. customizing
95-
kubeadm-config or specifying volume mounts. see [kind documentation](https://kind.sigs.k8s.io/docs/user/quick-start/#configuring-your-kind-cluster)
96-
for more details.
97-
98-
### Testing Kubernetes cluster variants
99-
100-
kinder gives you shortcuts for testing Kubernetes cluster variants supported by kubeadm:
101-
102-
```bash
103-
# create a cluster using kube-dns instead of CoreDNS
104-
kinder create cluster --kube-dns
105-
106-
# create a cluster using an external etcd
107-
kinder create cluster --external-etcd
108-
```
109-
110-
## Working on nodes
111-
112-
You can use `docker exec` and `docker cp` to work on nodes.
113-
114-
```bash
115-
# check the content of the /kind/kubeadm.conf file
116-
docker exec kind-control-plane cat kind/kubeadm.conf
117-
118-
# execute a command on the kind-control-plane container (the control-plane node)
119-
docker exec kind-worker1 \
120-
kubeadm init --config=/kind/kubeadm.conf --ignore-preflight-errors=all
121-
122-
# override the kubeadm binary on the on the kind-control-plane container
123-
# with a locally built kubeadm binary
124-
docker cp \
125-
$working_dir/kubernetes/bazel-bin/cmd/kubeadm/linux_amd64_pure_stripped/kubeadm \
126-
kind-control-plane:/usr/bin/kubeadm
127-
```
128-
129-
On top of that, kinder offers you three commands for helping you working on nodes:
130-
131-
- `kinder do` allowing you to execute actions (repetitive tasks/sequence of commands) on nodes
132-
- `kinder exec`, a topology aware wrapper on docker `docker exec`
133-
- `kinder cp`, a topology aware wrapper on docker `docker cp`
134-
135-
### kinder do
136-
137-
`kinder do` is the kinder swiss knife.
138-
139-
It allows to execute actions (repetitive tasks/sequence of commands) on one or more nodes
140-
in the local Kubernetes cluster.
141-
142-
```bash
143-
# Execute kubeadm init, installs the CNI plugin and copy the kubeconfig file on the host
144-
kinder do kubeadm-init
145-
```
146-
147-
All the actions implemented in kinder are by design "developer friendly", in the sense that
148-
all the command output will be echoed and all the step will be documented.
149-
Following actions are available:
150-
151-
| action | Notes |
152-
| --------------- | ------------------------------------------------------------ |
153-
| kubeadm-init | Executes the kubeadm-init workflow, installs the CNI plugin and then copies the kubeconfig file on the host machine. Available options are:<br /> `--use-phases` triggers execution of the init workflow by invoking single phases. <br />`--automatic-copy-certs` instruct kubeadm to use the automatic copy cert feature.|
154-
| manual-copy-certs | Implement the manual copy of certificates to be shared acress control-plane nodes (n.b. manual means not managed by kubeadm) Available options are:<br /> `--only-node` to execute this action only on a specific node. |
155-
| kubeadm-join | Executes the kubeadm-join workflow both on secondary control plane nodes and on worker nodes. Available options are:<br /> `--use-phases` triggers execution of the init workflow by invoking single phases.<br />`--automatic-copy-certs` instruct kubeadm to use the automatic copy cert feature.<br /> `--only-node` to execute this action only on a specific node. |
156-
| kubeadm-upgrade |Executes the kubeadm upgrade workflow and upgrading K8s. Available options are:<br /> `--upgrade-version` for defining the target K8s version.<br />`--only-node` to execute this action only on a specific node. |
157-
| Kubeadm-reset | Executes the kubeadm-reset workflow on all the nodes. Available options are:<br /> `--only-node` to execute this action only on a specific node. |
158-
| cluster-info | Returns a summary of cluster info including<br />- List of nodes<br />- list of pods<br />- list of images used by pods<br />- list of etcd members |
159-
| smoke-test | Implements a non-exhaustive set of tests that aim at ensuring that the most important functions of a Kubernetes cluster work |
160-
161-
### kinder exec
162-
163-
`kinder exec` provide a topology aware wrapper on docker `docker exec` .
164-
165-
```bash
166-
# check the kubeadm version on all the nodes
167-
kinder exec @all -- kubeadm version
168-
169-
# run kubeadm join on all the worker nodes
170-
kinder exec @w* -- kubeadm join 172.17.0.2:6443 --token abcdef.0123456789abcdef ...
171-
172-
# run kubectl command inside the bootstrap control-plane node
173-
kinder exec @cp1 -- kubectl --kubeconfig=/etc/kubernetes/admin.conf cluster-info
174-
```
175-
176-
Following node selectors are available
177-
178-
| selector | return the following nodes |
179-
| -------- | ------------------------------------------------------------ |
180-
| @all | all the Kubernetes nodes in the cluster.<br />(control-plane and worker nodes are included, load balancer and etcd not) |
181-
| @cp* | all the control-plane nodes |
182-
| @cp1 | the bootstrap-control plane node |
183-
| @cpN | the secondary master nodes |
184-
| @w* | all the worker nodes |
185-
| @lb | the external load balancer |
186-
| @etcd | the external etcd |
187-
188-
As alternative to node selector, the node name (the container name without the cluster name prefix) can be used to target actions to a specific node.
189-
190-
```bash
191-
# run kubeadm join on the first worker node node only
192-
kinder exec worker1 -- kubeadm join 172.17.0.2:6443 --token abcdef.0123456789abcdef ...
193-
```
194-
195-
### kinder cp
196-
197-
`kinder cp` provide a topology aware wrapper on docker `docker cp` . Following feature are supported:
198-
199-
```bash
200-
# copy to the host the /kind/kubeadm.conf file existing on the bootstrap control-plane node
201-
kinder cp @cp1:kind/kubeadm.conf kubeadm.conf
202-
203-
# copy to the bootstrap control-plane node a local kubeadm.conf file
204-
kinder cp kubeadm.conf @cp1:kind/kubeadm.conf
205-
206-
# override the kubeadm binary on all the nodes with a locally built kubeadm binary
207-
kinder cp \
208-
$working_dir/kubernetes/bazel-bin/cmd/kubeadm/linux_amd64_pure_stripped/kubeadm \
209-
@all:/usr/bin/kubeadm
210-
```
211-
212-
> Please note that, `docker cp` or `kinder cp` allows you to replace the kubeadm kinary on existing nodes. If you want to replace the kubeadm binary on nodes that you create in future, please check altering node images paragraph
213-
214-
## Altering node images
53+
## Usage
21554

216-
Kind can be estremely efficient when the node image contains all the necessary artifacts.
55+
Read the [kind documentation](https://kind.sigs.k8s.io/docs/user/quick-start/) first.
21756

218-
kinder allows kubeadm contributor to exploit this feature by implementing the `kinder build node-variant` command, that takes a node-image and allows to build variants by:
57+
Then [Prepare for tests](doc/prepare-for-tests.md)
21958

220-
- Adding new pre-loaded images that will be made available on all nodes at cluster creation time
221-
- Replacing the kubeadm binary installed in the cluster, e.g. with a locally build version of kubeadm
222-
- Adding deb packages for a second Kubernetes version to be used for upgrade testing
223-
224-
The above options can be combined toghether in one command, if necessary
225-
226-
### Add images
227-
228-
```bash
229-
kinder build node-variant \
230-
--base-image kindest/node:latest \
231-
--image kindest/node:PR12345 \
232-
--with-images $my-local-images/nginx.tar
233-
```
59+
Follow the how to guides:
23460

235-
Both single file or folder can be used as a arguments for the `--with-images`, but only image tar files will be considered; Image tar file will be placed in a well know folder, and kind(er) will load them during the initialization of each node.
236-
237-
### Replace kubeadm binary
238-
239-
```bash
240-
kinder build node-variant \
241-
--base-image kindest/node:latest \
242-
--image kindest/node:PR12345 \
243-
--with-kubeadm $working_dir/kubernetes/bazel-bin/cmd/kubeadm/linux_amd64_pure_stripped/kubeadm
244-
```
245-
246-
> Please note that, replacing the kubeadm binary in the node-images will have effect on nodes that you create in future; If you want to replace the kubeadm kinary on existing nodes, you should use `docker cp` or `kinder cp` instead.
247-
248-
### Add upgrade packages
249-
250-
```bash
251-
kinder build node-variant \
252-
--base-image kindest/node:latest \
253-
--image kindest/node:PR12345 \
254-
--with-upgrade-packages $my-local-packages/v1.12.2/
255-
```
61+
- [Getting started (test single control-plane)](doc/getting-started.md)
62+
- [Testing HA](doc/test-HA.md)
63+
- [Testing upgrades](doc/test-upgrades.md)
64+
- [Testing X on Y](doc/test-XonY.md)
25665

257-
Both single file or folder can be used as a arguments for the `--with-upgrade-packages`, but only deb packages will be considered; deb files will be placed in a well know folder, the kubeadm-upgrade action will use them during the upgrade sequence.
66+
Or have a look at the [Kinder reference](doc/reference.md)

kinder/cmd/kinder/build/build.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package build implements the `build` command
18+
package build
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
23+
"sigs.k8s.io/kind/cmd/kind/build/baseimage"
24+
"sigs.k8s.io/kind/cmd/kind/build/nodeimage"
25+
26+
"k8s.io/kubeadm/kinder/cmd/kinder/build/nodevariant"
27+
)
28+
29+
// NewCommand returns a new cobra.Command for building
30+
func NewCommand() *cobra.Command {
31+
cmd := &cobra.Command{
32+
Args: cobra.NoArgs,
33+
// TODO(bentheelder): more detailed usage
34+
Use: "build",
35+
Short: "Build one of [base-image, node-image, node-variant]",
36+
Long: "Build the base node image (base-image) or the node image (node-image) or node image variants (node-variant)",
37+
}
38+
// add subcommands
39+
cmd.AddCommand(baseimage.NewCommand())
40+
cmd.AddCommand(nodeimage.NewCommand())
41+
cmd.AddCommand(nodevariant.NewCommand())
42+
return cmd
43+
}

0 commit comments

Comments
 (0)