Skip to content

Commit 8a4eee5

Browse files
committed
Add quickstart example
1 parent 8c13651 commit 8a4eee5

8 files changed

Lines changed: 139 additions & 19 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: v1alpha1
2+
cluster:
3+
cloudProvider: devspace-cloud
4+
devSpace:
5+
deployments:
6+
- name: devspace-default
7+
kubectl:
8+
manifests:
9+
- kube/*
10+
ports:
11+
- labelSelector:
12+
release: devspace-default
13+
portMappings:
14+
- localPort: 3000
15+
remotePort: 3000
16+
sync:
17+
- containerPath: /app
18+
labelSelector:
19+
release: devspace-default
20+
localSubPath: ./
21+
uploadExcludePaths:
22+
- Dockerfile
23+
- .devspace/
24+
- chart/
25+
- vendor/
26+
images:
27+
default:
28+
name: yourdockername/quickstart
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Dockerfile
2+
.devspace/
3+
chart/
4+
node_modules/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:8.11.4
2+
3+
RUN mkdir /app
4+
WORKDIR /app
5+
6+
COPY package.json .
7+
RUN npm install
8+
9+
COPY . .
10+
11+
CMD ["npm", "start"]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Quickstart kubectl example
2+
3+
This example shows you how to develop a small node express application with devspace and devspace-cloud.
4+
5+
# Step 0: Prerequisites
6+
7+
In order to use this example, make sure you have docker installed and a docker registry where you can push to (hub.docker.com, gcr.io etc.). Make sure you are logged in to the registry via `docker login`.
8+
9+
Exchange the image name in `.devspace/config.yaml` under `images.default.name` with the image name you want to use. Do the same thing in `kube/deployment.yaml` under `spec.template.spec.image`. Do **not** add a tag to those image names, because this will be done at runtime automatically.
10+
11+
# Step 1: Start the devspace
12+
13+
To deploy the application to the devspace-cloud simply run `devspace up`. The output of the command should look similar to this:
14+
15+
```
16+
[INFO] Building image 'fabian1991/quickstart' with engine 'docker'
17+
[DONE] √ Authentication successful (hub.docker.com)
18+
Sending build context to Docker daemon 20.99kB
19+
Step 1/7 : FROM node:8.11.4
20+
---> 8198006b2b57
21+
Step 2/7 : RUN mkdir /app
22+
---> Using cache
23+
---> 2064997c60c5
24+
Step 3/7 : WORKDIR /app
25+
---> Using cache
26+
---> 6faeba82e3d7
27+
Step 4/7 : COPY package.json .
28+
---> Using cache
29+
---> cb24ee28e9eb
30+
Step 5/7 : RUN npm install
31+
---> Using cache
32+
---> a6ed836b6a83
33+
Step 6/7 : COPY . .
34+
---> f23d8c3c1c51
35+
Step 7/7 : CMD ["npm", "start"]
36+
---> Running in f1e2310d36e3
37+
---> 98fbe8f46c11
38+
Successfully built 98fbe8f46c11
39+
Successfully tagged fabian1991/quickstart:dk0dqqO
40+
The push refers to repository [docker.io/fabian1991/quickstart]
41+
28bb9f0f148c: Pushed
42+
090fce06793d: Layer already exists
43+
e342c5b21403: Layer already exists
44+
cbf8535e7a06: Layer already exists
45+
be0fb77bfb1f: Layer already exists
46+
63c810287aa2: Layer already exists
47+
2793dc0607dd: Layer already exists
48+
74800c25aa8c: Layer already exists
49+
ba504a540674: Layer already exists
50+
81101ce649d5: Layer already exists
51+
daf45b2cad9a: Layer already exists
52+
8c466bf4ca6f: Layer already exists
53+
dk0dqqO: digest: sha256:5e043c3d366676331f4ffe6a9b6f38cbc08338c25ef47789060564d3304153a2 size: 2839
54+
[INFO] Image pushed to registry (hub.docker.com)
55+
[DONE] √ Done building and pushing image 'fabian1991/quickstart'
56+
[INFO] Deploying devspace-default with kubectl
57+
deployment.extensions/devspace created
58+
[DONE] √ Successfully deployed devspace-default
59+
[DONE] √ Port forwarding started on 3000:3000
60+
[DONE] √ Sync started on /Users/fabiankramm/Programmieren/go-workspace/src/github.com/covexo/devspace/examples/quickstart-kubectl <-> /app (Pod:e388779b2b49465855bb0322057a9fff/devspace-5b5f977b77-49cjt)
61+
root@devspace-5b5f977b77-49cjt:/app#
62+
```
63+
64+
The command created a new kubernetes namespace for you in the devspace-cloud and deployed the `kube/deployment.yaml` to that namespace. It also created a new kubectl context for you. If you want to access kubernetes resources via kubectl in the devspace-cloud you can simply change your kubectl context via `kubectl config use-context $$devspace-context-name$$`. You can find the context name in `.devspace/config.yaml` under `cluster.kubeContext`.
65+
66+
# Step 2: Start developing
67+
68+
You can start the server now with `npm start` in the open terminal. Now navigate in your browser to `localhost:3000` and you should see the output 'Hello World!'.
69+
70+
You can easily change any code within the `index.js` and restart the server with `npm start` and you should see the changes immediately, without the need of rebuilding the docker file or redeploying the chart.
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
apiVersion: extensions/v1beta1
22
kind: Deployment
3+
metadata:
4+
name: devspace
35
spec:
46
replicas: 1
57
template:
@@ -9,13 +11,6 @@ spec:
911
spec:
1012
containers:
1113
- name: default
12-
image: devspace-default
13-
command:
14-
args:
15-
{{- range $index, $arg := .Values.containers.default.args }}
16-
- "{{ $arg }}"
17-
{{- end }}
18-
imagePullSecrets:
19-
{{- range $index, $secretName := .Values.pullSecrets }}
20-
- name: "{{ $secretName }}"
21-
{{- end }}
14+
image: yourdockername/quickstart
15+
command: ["sleep"]
16+
args: ["999999999999"]

pkg/devspace/deploy/kubectl/walk.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package kubectl
22

3-
import "github.com/covexo/devspace/pkg/util/log"
4-
53
// ReplaceFn defines the replace function
64
type ReplaceFn func(value string) string
75

@@ -20,13 +18,10 @@ func Walk(d interface{}, match MatchFn, replace ReplaceFn) {
2018
key := k.(string)
2119
value, ok := v.(string)
2220
if ok == false {
23-
log.Infof("Key %s is no string", key)
24-
2521
Walk(v, match, replace)
2622
continue
2723
}
2824

29-
log.Infof("Key %s is string", key)
3025
if match(key, value) {
3126
t[k] = replace(value)
3227
}

pkg/devspace/kubectl/client.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ func IsMinikube() bool {
161161

162162
// GetNewestRunningPod retrieves the first pod that is found that has the status "Running" using the label selector string
163163
func GetNewestRunningPod(kubectl *kubernetes.Clientset, labelSelector, namespace string) (*k8sv1.Pod, error) {
164+
config := configutil.GetConfig()
165+
166+
if namespace == "" {
167+
defaultNamespace, err := configutil.GetDefaultNamespace(config)
168+
if err != nil {
169+
return nil, err
170+
}
171+
172+
namespace = defaultNamespace
173+
}
174+
164175
maxWaiting := 120 * time.Second
165176
waitingInterval := 1 * time.Second
166177

@@ -171,6 +182,8 @@ func GetNewestRunningPod(kubectl *kubernetes.Clientset, labelSelector, namespace
171182
LabelSelector: labelSelector,
172183
})
173184
if err != nil {
185+
log.Info("Error here")
186+
174187
return nil, err
175188
}
176189

@@ -322,7 +335,6 @@ func GetPodsFromDeployment(kubectl *kubernetes.Clientset, deployment, namespace
322335
// ForwardPorts forwards the specified ports from the cluster to the local machine
323336
func ForwardPorts(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, ports []string, stopChan chan struct{}, readyChan chan struct{}) error {
324337
config, err := GetClientConfig()
325-
326338
if err != nil {
327339
return err
328340
}
@@ -334,7 +346,6 @@ func ForwardPorts(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, ports []s
334346
SubResource("portforward")
335347

336348
transport, upgrader, err := spdy.RoundTripperFor(config)
337-
338349
if err != nil {
339350
return err
340351
}

pkg/devspace/services/port_forwarding.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func StartPortForwarding(client *kubernetes.Clientset, log log.Logger) error {
3333
log.StartWait("Waiting for pods to become running")
3434
pod, err := kubectl.GetNewestRunningPod(client, strings.Join(labels, ", "), namespace)
3535
log.StopWait()
36+
3637
if err != nil {
3738
return fmt.Errorf("Unable to list devspace pods: %s", err.Error())
3839
} else if pod != nil {
@@ -44,13 +45,18 @@ func StartPortForwarding(client *kubernetes.Clientset, log log.Logger) error {
4445

4546
readyChan := make(chan struct{})
4647

47-
go kubectl.ForwardPorts(client, pod, ports, make(chan struct{}), readyChan)
48+
go func() {
49+
err := kubectl.ForwardPorts(client, pod, ports, make(chan struct{}), readyChan)
50+
if err != nil {
51+
log.Errorf("Error starting port forwarding: %v", err)
52+
}
53+
}()
4854

4955
// Wait till forwarding is ready
5056
select {
5157
case <-readyChan:
5258
log.Donef("Port forwarding started on %s", strings.Join(ports, ", "))
53-
case <-time.After(5 * time.Second):
59+
case <-time.After(20 * time.Second):
5460
return fmt.Errorf("Timeout waiting for port forwarding to start")
5561
}
5662
}

0 commit comments

Comments
 (0)