Skip to content

Commit

Permalink
Use sideloading from pre-built docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Apr 28, 2020
1 parent 1fb185c commit 2d21f74
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 80 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,39 @@ Birth Dependency:

## Install

**TODO**: Alpine & Ubuntu Docker images for multi-stage builds.

Build from source:

```
go get github.com/karlkfi/kubexit/cmd/kubexit
```

Copy from pre-built Alpine-based container image in a multi-stage build:

```
FROM karlkfi/kubexit:latest AS kubexit
FROM alpine:3.11
RUN apk --no-cache add ca-certificates tzdata
COPY --from=kubexit /bin/kubexit /bin/
ENTRYPOINT ["kubexit"]
```

Copy from init container to ephemeral volume:

```
volumes:
- name: kubexit
emptyDir: {}
initContainers:
- name: kubexit
image: karlkfi/kubexit:latest
command: ['cp', '/bin/kubexit', '/kubexit/kubexit']
volumeMounts:
- mountPath: /kubexit
name: kubexit
```

## Examples

- [Client Server Job](examples/client-server-job/)
Expand Down
4 changes: 1 addition & 3 deletions examples/client-server-job/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Example: Clinet Server Job

This example has 3 containers:
- `kubexit` - An init container that builds kubexit and stores it in an ephemeral volume for the other containers to use. Ideally, you would use a pre-built image instead, for faster startup. But this way you can test new source code.
- `kubexit` - An init container that builds kubexit and stores it in an ephemeral volume for the other containers to use.
- `client` - An alpine container that installs curl, sleeps until the server is ready (birth dependency), curls the server, and then exits.
- `server` - An nginx container that sleeps (to exemplify slow startup), and then starts serving traffic. When the client exits, the server will exit (death dependency).

Expand All @@ -12,8 +12,6 @@ kubectl apply -f examples/client-server-job/job.yaml
POD_NAME="$(kubectl get pod -l app=example-job --no-headers=true -o=custom-columns='DATA:metadata.name')"
kubectl logs "${POD_NAME}" -f -c kubexit 2>&1 | tee examples/client-server-job/kubexit.log
sleep 5
kubectl logs "${POD_NAME}" -f -c client 2>&1 | tee examples/client-server-job/client.log
kubectl logs "${POD_NAME}" -f -c server 2>&1 | tee examples/client-server-job/server.log
Expand Down
44 changes: 22 additions & 22 deletions examples/client-server-job/client.log
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,63 @@ Tombstone: /graveyard/client
Birth Deps: server
Death Deps: N/A
Grace Period: 30s
Pod Name: example-job-tsq2p
Pod Name: example-job-kflt8
Namespace: default
Watching pod updates...
Event Type: ADDED
Event Type: MODIFIED
Pod Watch(example-job-kflt8): done
All birth deps ready: server
Exec: /usr/bin/curl -v --fail http://localhost:80/
Pod Watch(example-job-tsq2p): done
Creating tombstone: /graveyard/client
% Total % Received % Xferd Average Speed Time Time Time Current
% Total % ReceCreating tombstone: /graveyard/client
ived % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1:80...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.67.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.17.10
< Date: Tue, 28 Apr 2020 10:41:47 GMT
< Content-Type: text/html
< Content-Length: 612
< Last-Modified: Tue, 14 Apr 2020 14:46:22 GMT
< Connection: keep-alive
< ETag: "5e95ccbe-264"
< Accept-Ranges: bytes
<
{ [612 bytes data]
100 612 100 612 0 0 14571 0 --:--:-- --:--:-- --:--:-- 15300
<!DOCTYPE html>
* Connection #0 to host localhost left intact
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
Exit(0)
Updating tombstone: /graveyard/client
margin: 0 auto;
> Accept: */*
font-family: Tahoma, Verdana, Arial, sans-serif;
>
}
* Mark bundle as not supporting multiuse
</style>
< HTTP/1.1 200 OK
</head>
< Server: nginx/1.17.10
< Date: Tue, 28 Apr 2020 09:42:39 GMT
<body>
< Content-Type: text/html
<h1>Welcome to nginx!</h1>
< Content-Length: 612
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
< Last-Modified: Tue, 14 Apr 2020 14:46:22 GMT
< Connection: keep-alive

< ETag: "5e95ccbe-264"
<p>For online documentation and support please refer to
< Accept-Ranges: bytes
<a href="http://nginx.org/">nginx.org</a>.<br/>
<
Commercial support is available at
{ [612 bytes data]
<a href="http://nginx.com/">nginx.com</a>.</p>
100 612 100 612 0 0 199k 0 --:--:-- --:--:-- --:--:-- 199k

* Connection #0 to host localhost left intact
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Exit(0)
Updating tombstone: /graveyard/client
Expand Down
14 changes: 2 additions & 12 deletions examples/client-server-job/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,8 @@ spec:

initContainers:
- name: kubexit
image: golang:1.14.1-alpine3.11
command: ['sh', '-c']
args:
- |
set -o errexit -o nounset -o pipefail
apk --no-cache add git
mkdir /build
cd /build
git clone https://github.com/karlkfi/kubexit .
git checkout "karl-birth-deps"
CGO_ENABLED=0 GOOS=linux go build -o /kubexit/kubexit ./cmd/kubexit
echo "kubexit -> /kubexit/kubexit"
image: karlkfi/kubexit:latest
command: ['cp', '/bin/kubexit', '/kubexit/kubexit']
volumeMounts:
- mountPath: /kubexit
name: kubexit
Expand Down
39 changes: 0 additions & 39 deletions examples/client-server-job/kubexit.log

This file was deleted.

6 changes: 4 additions & 2 deletions examples/client-server-job/server.log
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Tombstone modified: client
Reading tombstone: client
Tombstone modified: client
Reading tombstone: client
127.0.0.1 - - [28/Apr/2020:09:42:39 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.67.0" "-"
Tombstone modified: client
Reading tombstone: client
127.0.0.1 - - [28/Apr/2020:10:41:47 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.67.0" "-"
Tombstone modified: client
Reading tombstone: client
New death: client
Tombstone(client): &{Born:2020-04-28 09:42:39.1738453 +0000 UTC Died:2020-04-28 09:42:39.1960628 +0000 UTC ExitCode:0xc0000b0200 Graveyard:/graveyard Name:client fileLock:{state:0 sema:0}}
Tombstone(client): {"Born":"2020-04-28T10:41:46.9926314Z","Died":"2020-04-28T10:41:47.0498724Z","ExitCode":0}
Terminating child process...
Tombstone Watch(/graveyard): done
Exit(0)
Expand Down

0 comments on commit 2d21f74

Please sign in to comment.