Skip to content

Commit

Permalink
Add a tutorial for kruise controllers (#25)
Browse files Browse the repository at this point in the history
* add a tutorial for kruise controllers

* update readme

* update readme

* update readme

* update command
  • Loading branch information
jian-he authored and FillZpp committed Jun 21, 2019
1 parent db2a323 commit d3efc65
Show file tree
Hide file tree
Showing 23 changed files with 915 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Today, Kruise offers three application workload controllers:

Please see [documents](./docs/README.md) for more technical information.

A [tutorial](./docs/tutorial/README.md) is provided to demonstrate how to use the workload controllers.

## Getting started

### Install with YAML files
Expand Down Expand Up @@ -66,14 +68,19 @@ spec:
app: sample
spec:
readinessGates:
- conditionType: InPlaceUpdateReady # A new condition that ensures the pod reamin at NotReady state while the in-place update is happening
# A new condition must be added to ensure the pod remain at NotReady state while the in-place update is happening
- conditionType: InPlaceUpdateReady
containers:
- name: main
image: nginx:alpine
podManagementPolicy: Parallel # allow parallel updates, works together with maxUnavailable
updateStrategy:
type: RollingUpdate
rollingUpdate:
# Do in-place update if possible, currently only image update is supported for in-place update
podUpdatePolicy: InPlaceIfPossible
# Allow parallel updates with max number of unavailable instances equals to 2
maxUnavailable: 2
```
### Broadcast Job
Run a BroadcastJob that each Pod computes pi, with `ttlSecondsAfterFinished` set to 30. The job
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: openkruise/kruise-manager:v0.1.0
- image: openkruise/kruise-manager:daily
name: manager
args:
- "--metrics-addr=127.0.0.1:8080"
Expand Down
5 changes: 5 additions & 0 deletions docs/astatefulset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ spec:
app: sample
spec:
readinessGates:
# A new condition that ensures the pod remains at NotReady state while the in-place update is happening
- conditionType: InPlaceUpdateReady
containers:
- name: main
image: nginx:alpine
podManagementPolicy: Parallel # allow parallel updates, works together with maxUnavailable
updateStrategy:
type: RollingUpdate
rollingUpdate:
# Do in-place update if possible, currently only image update is supported for in-place update
podUpdatePolicy: InPlaceIfPossible
# Allow parallel updates with max number of unavailable instances equals to 2
maxUnavailable: 2
```
324 changes: 324 additions & 0 deletions docs/tutorial/README.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions docs/tutorial/v1/broadcastjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apps.kruise.io/v1alpha1
kind: BroadcastJob
metadata:
name: download-image
spec:
template:
spec:
containers:
- name: guestbook
image: openkruise/guestbook:v2
command: ["echo", "started"] # a dummy command to do nothing
restartPolicy: Never
completionPolicy:
type: Always
ttlSecondsAfterFinished: 60 # the job will be deleted after 60 seconds
17 changes: 17 additions & 0 deletions docs/tutorial/v1/guestbook-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: guestbook
labels:
app: guestbook
spec:
ports:
- port: 3000
targetPort: http-server
name: main-port
- port: 4000
targetPort: sidecar-server
name: sidecar-port
selector:
app: guestbook
type: LoadBalancer
Binary file added docs/tutorial/v1/guestbook-sidecar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/tutorial/v1/guestbook-sidecar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apps.kruise.io/v1alpha1
kind: SidecarSet
metadata:
name: guestbook-sidecar
spec:
selector: # select the pods to be injected with sidecar containers
matchLabels:
app: guestbook
containers:
- name: guestbook-sidecar
image: openkruise/guestbook:sidecar
imagePullPolicy: Always
ports:
- name: sidecar-server
containerPort: 4000 # different from main guestbook containerPort which is 3000
37 changes: 37 additions & 0 deletions docs/tutorial/v1/guestbook-statefulset-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: apps.kruise.io/v1alpha1
kind: StatefulSet
metadata:
name: guestbook-v1
labels:
app: guestbook
version: "1.0"
spec:
replicas: 20
serviceName: guestbook
selector:
matchLabels:
app: guestbook
template:
metadata:
labels:
app: guestbook
version: "1.0"
spec:
readinessGates:
# A new condition that ensures the pod remains at NotReady state while the in-place update is happening
- conditionType: InPlaceUpdateReady
containers:
- name: guestbook
image: openkruise/guestbook:v2
ports:
- name: http-server
containerPort: 3000
podManagementPolicy: Parallel # allow parallel updates, works together with maxUnavailable
updateStrategy:
type: RollingUpdate
rollingUpdate:
# Do in-place update if possible, currently only image update is supported for in-place update
podUpdatePolicy: InPlaceIfPossible
# Allow parallel updates with max number of unavailable instances equals to 2
maxUnavailable: 3
partition: 15
36 changes: 36 additions & 0 deletions docs/tutorial/v1/guestbook-statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps.kruise.io/v1alpha1
kind: StatefulSet
metadata:
name: guestbook-v1
labels:
app: guestbook
version: "1.0"
spec:
replicas: 20
serviceName: guestbook
selector:
matchLabels:
app: guestbook
template:
metadata:
labels:
app: guestbook
version: "1.0"
spec:
readinessGates:
# A new condition that ensures the pod remains at NotReady state while the in-place update is happening
- conditionType: InPlaceUpdateReady
containers:
- name: guestbook
image: openkruise/guestbook:v1
ports:
- name: http-server
containerPort: 3000
podManagementPolicy: Parallel # allow parallel updates, works together with maxUnavailable
updateStrategy:
type: RollingUpdate
rollingUpdate:
# Do in-place update if possible, currently only image update is supported for in-place update
podUpdatePolicy: InPlaceIfPossible
# Allow parallel updates with max number of unavailable instances equals to 2
maxUnavailable: 3
Binary file added docs/tutorial/v1/guestbook.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/tutorial/v1/guestbook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guestbook
18 changes: 18 additions & 0 deletions docs/tutorial/v1/guestbook/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang as builder
RUN go get github.com/codegangsta/negroni
RUN go get github.com/gorilla/mux github.com/xyproto/simpleredis
COPY main.go .
RUN go build main.go

FROM busybox:ubuntu-14.04

COPY --from=builder /go//main /app/guestbook

ADD public/index.html /app/public/index.html
ADD public/script.js /app/public/script.js
ADD public/style.css /app/public/style.css
ADD public/jquery.min.js /app/public/jquery.min.js

WORKDIR /app
CMD ["./guestbook"]
EXPOSE 3000
26 changes: 26 additions & 0 deletions docs/tutorial/v1/guestbook/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build the guestbook example
# Usage:
# [VERSION=v1] [REGISTRY="docker.io/ibmcom"] make build

VERSION?=v1
REGISTRY?=openkruise

all: build

release: clean build push clean

# Builds a docker image that builds the app and packages it into a
# minimal docker image
build:
docker build --pull -t "${REGISTRY}/guestbook:${VERSION}" .

# push the image to an registry
push: build
docker push ${REGISTRY}/guestbook:${VERSION}

# remove previous images and containers
clean:
rm -f guestbook/guestbook
docker rmi -f "${REGISTRY}/guestbook:${VERSION}" || true

.PHONY: release clean build push
Loading

0 comments on commit d3efc65

Please sign in to comment.