Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# JetBrains project configuration
.idea/
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

152 changes: 152 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
branch = "master"
name = "github.com/comail/colog"

[[constraint]]
name = "github.com/julienschmidt/httprouter"
version = "1.3.0"

[[constraint]]
branch = "master"
name = "k8s.io/api"

[[constraint]]
name = "k8s.io/kubernetes"
version = "1.16.3"

[prune]
go-tests = true
unused-packages = true
86 changes: 12 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,18 @@
# k8s-scheduler-extender-example
This is an example of [Kubernetes Scheduler Extender](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/scheduling/scheduler_extender.md)
This is a repo forked from an [k8s scheduler extender example](https://github.com/everpeace/k8s-scheduler-extender-example)
developed by @everpeace.

## How to
We restructured the code to wrap all shared functions and variables into a package `k8s-scheduler-extender`.
Other referenced packages including `kubernetes` are copied to `vendor`.

### 0. checkout the repo

```shell
$ git clone [email protected]:everpeace/k8s-scheduler-extender-example.git
$ cd k8s-scheduler-extender-example
$ git submodule update --init
```

### 1. buid a docker image

```
$ IMAGE=YOUR_ORG/YOUR_IMAGE:YOUR_TAG

$ docker build . -t "${IMAGE}"
$ docker push "${IMAGE}"
```

### 2. deploy `my-scheduler` in `kube-system` namespace
please see ConfigMap in [extender.yaml](extender.yaml) for scheduler policy json which includes scheduler extender config.

```
# bring up the kube-scheduler along with the extender image you've just built
$ sed 's/a\/b:c/'$(echo "${IMAGE}" | sed 's/\//\\\//')'/' extender.yaml | kubectl apply -f -
```

For ease of observation, start streaming logs from the extender:

```console
$ kubectl -n kube-system logs deploy/my-scheduler -c my-scheduler-extender-ctr -f
[ warn ] 2018/11/07 08:41:40 main.go:84: LOG_LEVEL="" is empty or invalid, fallling back to "INFO".
[ info ] 2018/11/07 08:41:40 main.go:98: Log level was set to INFO
[ info ] 2018/11/07 08:41:40 main.go:116: server starting on the port :80
## Usage
You can reference the functions and variables by import the package.
```golang
import "github.com/wangchen615/k8s-scheduler-extender-example/k8s_scheduler_extender"
```

Open up an another termianl and proceed.
The `main.go` is an example extender revised using the above reference.

### 3. schedule test pod

you will see `test-pod` will be scheduled by `my-scheduler`.

```
$ kubectl create -f test-pod.yaml

$ kubectl describe pod test-pod
Name: test-pod
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 25s my-scheduler Successfully assigned test-pod to minikube
Normal SuccessfulMountVolume 25s kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-wrk5s"
Normal Pulling 24s kubelet, minikube pulling image "nginx"
Normal Pulled 8s kubelet, minikube Successfully pulled image "nginx"
Normal Created 8s kubelet, minikube Created container
Normal Started 8s kubelet, minikube Started container
```


## License

```
Copyright 2018 Shingo Omura <https://github.com/everpeace>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
## Used packages
The dependency graph of all packages used can be found below.
![](dep.png)
80 changes: 80 additions & 0 deletions README.md.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# k8s-scheduler-extender-example
This is an example of [Kubernetes Scheduler Extender](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/scheduling/scheduler_extender.md)

## How to

### 0. checkout the repo

```shell
$ git clone [email protected]:everpeace/k8s-scheduler-extender-example.git
$ cd k8s-scheduler-extender-example
$ git submodule update --init
```

### 1. buid a docker image

```
$ IMAGE=YOUR_ORG/YOUR_IMAGE:YOUR_TAG

$ docker build . -t "${IMAGE}"
$ docker push "${IMAGE}"
```

### 2. deploy `my-scheduler` in `kube-system` namespace
please see ConfigMap in [extender.yaml](extender.yaml) for scheduler policy json which includes scheduler extender config.

```
# bring up the kube-scheduler along with the extender image you've just built
$ sed 's/a\/b:c/'$(echo "${IMAGE}" | sed 's/\//\\\//')'/' extender.yaml | kubectl apply -f -
```

For ease of observation, start streaming logs from the extender:

```console
$ kubectl -n kube-system logs deploy/my-scheduler -c my-scheduler-extender-ctr -f
[ warn ] 2018/11/07 08:41:40 main.go:84: LOG_LEVEL="" is empty or invalid, fallling back to "INFO".
[ info ] 2018/11/07 08:41:40 main.go:98: Log level was set to INFO
[ info ] 2018/11/07 08:41:40 main.go:116: server starting on the port :80
```

Open up an another termianl and proceed.

### 3. schedule test pod

you will see `test-pod` will be scheduled by `my-scheduler`.

```
$ kubectl create -f test-pod.yaml

$ kubectl describe pod test-pod
Name: test-pod
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 25s my-scheduler Successfully assigned test-pod to minikube
Normal SuccessfulMountVolume 25s kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-wrk5s"
Normal Pulling 24s kubelet, minikube pulling image "nginx"
Normal Pulled 8s kubelet, minikube Successfully pulled image "nginx"
Normal Created 8s kubelet, minikube Created container
Normal Started 8s kubelet, minikube Started container
```


## License

```
Copyright 2018 Shingo Omura <https://github.com/everpeace>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
Binary file added dep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading