|
| 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. |
0 commit comments