Skip to content

Commit 54b8c33

Browse files
committed
Add kaniko-minikube example
1 parent 8d973ff commit 54b8c33

11 files changed

Lines changed: 191 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
logs/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: v1alpha1
2+
cluster:
3+
kubeContext: minikube
4+
namespace: test
5+
devSpace:
6+
deployments:
7+
- helm:
8+
chartPath: ./chart
9+
name: devspace-default
10+
ports:
11+
- labelSelector:
12+
release: devspace-default
13+
portMappings:
14+
- localPort: 8080
15+
remotePort: 8080
16+
sync:
17+
- containerPath: /app
18+
labelSelector:
19+
release: devspace-default
20+
localSubPath: ./
21+
uploadExcludePaths:
22+
- Dockerfile
23+
- .devspace/
24+
- chart/
25+
images:
26+
default:
27+
build:
28+
kaniko:
29+
cache: true
30+
name: devspace
31+
registry: internal
32+
internalRegistry:
33+
deploy: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
registries:
2+
internal:
3+
auth:
4+
password: 58prtrR8tjNS
5+
username: user-7IS6l
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dockerfile
2+
.devspace/
3+
chart/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:1.11
2+
3+
RUN mkdir -p "$GOPATH/src/app" && ln -s $GOPATH/src/app /app
4+
ADD . $GOPATH/src/app
5+
6+
RUN cd $GOPATH/src/app && go get ./... && go build . && cd /app
7+
8+
WORKDIR /app
9+
CMD ["$GOPATH/src/app/app"]

examples/kaniko-minikube/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Kaniko example
2+
3+
This example shows how kaniko can be used instead of docker to build and push an docker image directly inside the cluster.
4+
5+
# Step 0: Prerequisites
6+
7+
In order to use this example, make sure you have a working minikube setup (you don't need an additional docker daemon or docker registry, because devspace can use the internal minikube docker daemon and will deploy a registry for you). See [install minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) for more details.
8+
9+
# Step 1: Start the devspace
10+
11+
To deploy the application to minikube simply run `devspace up`. The output of the command should look similar to this:
12+
13+
```
14+
[INFO] Create namespace test
15+
[DONE] √ Tiller started
16+
[DONE] √ Internal registry started
17+
[INFO] Building image 'devspace' with engine 'kaniko'
18+
[DONE] √ Authentication successful (10.107.78.184:5000)
19+
[DONE] √ Kaniko build pod started
20+
[DONE] √ Uploaded files to container
21+
[INFO] build >>> WARN[0001] Error while retrieving image from cache: getting image from path: open /cache/sha256:df8db4a3a7dee9782e0f1bdcc9d676bc2de0dc1d2dc2952d9b9b3718445b1455: no such file or directory
22+
[INFO] build >>> INFO[0001] Downloading base image golang:1.11
23+
[INFO] build >>> 2018/10/18 11:54:05 No matching credentials were found, falling back on anonymous
24+
[INFO] build >>> INFO[0002] Executing 0 build triggers
25+
[INFO] build >>> INFO[0002] Extracting layer 0
26+
[INFO] build >>> INFO[0014] Extracting layer 1
27+
[INFO] build >>> INFO[0017] Extracting layer 2
28+
[INFO] build >>> INFO[0018] Extracting layer 3
29+
[INFO] build >>> INFO[0029] Extracting layer 4
30+
[INFO] build >>> INFO[0042] Extracting layer 5
31+
[INFO] build >>> INFO[0076] Extracting layer 6
32+
[INFO] build >>> INFO[0076] Taking snapshot of full filesystem...
33+
[INFO] build >>> INFO[0090] RUN mkdir -p "$GOPATH/src/app" && ln -s $GOPATH/src/app /app
34+
[INFO] build >>> INFO[0090] Checking for cached layer 10.107.78.184:5000/devspace/cache:f141885fc82d849f3eba2d72bf74ce9842b3f9874ef5b003dd9b846726ee46b4...
35+
[INFO] build >>> INFO[0090] No cached layer found, executing command...
36+
[INFO] build >>> INFO[0090] cmd: /bin/sh
37+
[INFO] build >>> INFO[0090] args: [-c mkdir -p "$GOPATH/src/app" && ln -s $GOPATH/src/app /app]
38+
[INFO] build >>> INFO[0090] Using files from context: [/src]
39+
[INFO] build >>> INFO[0090] ADD . $GOPATH/src/app
40+
[INFO] build >>> INFO[0090] RUN cd $GOPATH/src/app && go get ./... && go build . && cd /app
41+
[INFO] build >>> INFO[0090] Checking for cached layer 10.107.78.184:5000/devspace/cache:3ade7ab92e4a6e6d8d57c98137a987ed85d67ba1446c2d92be842d14dd44ea67...
42+
[INFO] build >>> INFO[0090] No cached layer found, executing command...
43+
[INFO] build >>> INFO[0090] cmd: /bin/sh
44+
[INFO] build >>> INFO[0090] args: [-c cd $GOPATH/src/app && go get ./... && go build . && cd /app]
45+
[INFO] build >>> INFO[0093] WORKDIR /app
46+
[INFO] build >>> INFO[0093] cmd: workdir
47+
[INFO] build >>> INFO[0093] Changed working directory to /app
48+
[INFO] build >>> INFO[0093] CMD ["$GOPATH/src/app/app"]
49+
[INFO] build >>> INFO[0093] Taking snapshot of full filesystem...
50+
[INFO] build >>> 2018/10/18 11:55:48 pushed blob sha256:af3d9268d1a6b25f664130670edb460efcb7dd6e22f58efcc6cef2714c7a7efe
51+
[INFO] build >>> 2018/10/18 11:55:49 pushed blob sha256:202760eb4a0043cd84cd9971c47052617855ff653abec8ae479e89d369afd500
52+
[INFO] build >>> 2018/10/18 11:55:49 pushed blob sha256:8e9d103264e8425af20c8ae84535d73008e5accc340f95e9e3e155132053bae4
53+
[INFO] build >>> 2018/10/18 11:55:55 pushed blob sha256:e5c3f8c317dc30af45021092a3d76f16ba7aa1ee5f18fec742c84d4960818580
54+
[INFO] build >>> 2018/10/18 11:56:02 pushed blob sha256:193a6306c92af328dbd41bbbd3200a2c90802624cccfe5725223324428110d7f
55+
[INFO] build >>> 2018/10/18 11:56:35 pushed blob sha256:bc9ab73e5b14b9fbd3687a4d8c1f1360533d6ee9ffc3f5ecc6630794b40257b7
56+
[INFO] build >>> 2018/10/18 11:56:36 pushed blob sha256:a587a86c9dcb9df6584180042becf21e36ecd8b460a761711227b4b06889a005
57+
[INFO] build >>> 2018/10/18 11:56:41 pushed blob sha256:1bc310ac474b880a5e4aeec02e6423d1304d137f1a8990074cb3ac6386a0b654
58+
[INFO] build >>> 2018/10/18 11:56:59 pushed blob sha256:997731689cfbc58c8e74f2a20079338ce66965a40b21f27169b3d5a45ab61cbd
59+
[INFO] build >>> 2018/10/18 11:56:59 10.107.78.184:5000/devspace:JMNVk87: digest: sha256:6f9cc913b59a167050c9d65deb9677870880b27ccd842155980673f11a4cc205 size: 1578
60+
[DONE] √ Done building image
61+
[INFO] Image pushed to registry (10.107.78.184:5000)
62+
[DONE] √ Done building and pushing image '10.107.78.184:5000/devspace'
63+
[INFO] Deploying devspace-default with helm
64+
[DONE] √ Deployed helm chart (Release revision: 1)
65+
[DONE] √ Successfully deployed devspace-default
66+
[DONE] √ Port forwarding started on 8080:8080
67+
[DONE] √ Sync started on /go-workspace/src/github.com/covexo/devspace/examples/kaniko-minikube <-> /app (Pod: test/devspace-default-749f45ddcc-vgp4z)
68+
root@devspace-default-749f45ddcc-vgp4z:/go/src/app#
69+
```
70+
71+
The command created a test namespace, deployed a tiller server and internal registry and used a kaniko build pod to build the dockerfile.
72+
73+
Furthermore a bi-directional sync was started between the local folder `/go-workspace/src/github.com/covexo/devspace/examples/kaniko-minikube` and `/app` within the docker container. Whenever you change a file in either of those two folders the change will be synchronized. In addition the container port 8080 was forwarded to your local port 8080.
74+
75+
# Step 2: Start developing
76+
77+
You can start the server now with `go run main.go` in the open terminal. Now navigate in your browser to `localhost:8080` and you should see the output 'Hello World!'.
78+
79+
Change something in `main.go` and re-run `go run main.go`. Now just refresh your browser and you should see the changes immediately.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: my-app
2+
version: v0.0.1
3+
description: A Kubernetes-Native Application
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Release.Name }}
5+
labels:
6+
release: "{{ .Release.Name }}"
7+
spec:
8+
replicas: 1
9+
template:
10+
metadata:
11+
annotations:
12+
revision: "{{ .Release.Revision }}"
13+
labels:
14+
release: "{{ .Release.Name }}"
15+
spec:
16+
containers:
17+
- name: default
18+
image: "{{ .Values.containers.default.image }}"
19+
command:
20+
{{- range $index, $command := .Values.containers.default.command }}
21+
- "{{ $command }}"
22+
{{- end }}
23+
args:
24+
{{- range $index, $arg := .Values.containers.default.args }}
25+
- "{{ $arg }}"
26+
{{- end }}
27+
imagePullSecrets:
28+
{{- range $index, $secretName := .Values.pullSecrets }}
29+
- name: "{{ $secretName }}"
30+
{{- end }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
containers:
2+
default:
3+
image: "will be overriden by devspace up"
4+
command:
5+
- sleep
6+
args:
7+
- 99999999
8+
9+
pullSecrets: []

examples/kaniko-minikube/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
func handler(w http.ResponseWriter, r *http.Request) {
9+
fmt.Fprintf(w, "Hello World!")
10+
}
11+
12+
func main() {
13+
fmt.Println("Started server on :8080")
14+
15+
http.HandleFunc("/", handler)
16+
http.ListenAndServe(":8080", nil)
17+
}

0 commit comments

Comments
 (0)