Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Feature/demo prep #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions deploy/skaffold/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: go-slalom
data:
# property-like keys; each key maps to a simple value
magic_value: "TODO"
6 changes: 6 additions & 0 deletions deploy/skaffold/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ spec:
command:
- go-slalom
- start
env:
- name: MAGIC_VALUE
valueFrom:
configMapKeyRef:
name: go-slalom
key: magic_value
ports:
- name: http
containerPort: 8080
Expand Down
14 changes: 10 additions & 4 deletions docs/build-go-slalom.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go-slalom demonstrates how to create a basic service to run in kubernetes. The s
- endpoints for enabling/disabling readiness and liveness endpoints
- endpoint for basic service information

### build go-slalom
## build go-slalom

First lets clone and build go-slalom locally

Expand All @@ -27,7 +27,7 @@ cd go-slalom
go build
```

### go-slalom cli
## go-slalom cli

go-slalom includes a basic cli built using [cobra](https://github.com/spf13/cobra). It is common in go to build a cli
for starting a service and/or administering the service. Lets check it out
Expand All @@ -48,20 +48,22 @@ func main() {
The package `cmd` contains the commands. The file `root.go` implements the root command and the other files implement
sub commands. corba provides a clean cli.

## start go-slalom

### start go-slalom
One of the cli commands is `start`. Run it to start ther server

```bash
./go-slalom start
```

You should see logging similar to below.

```bash
{"level":"info","msg":"Starting server...","service":"api","time":"2019-05-09T13:22:03-07:00"}
```

In a separate console run `curl localhost:8008/version`. You should see similar output
In a separate console run `curl localhost:8008/version`. You should see similar output

```bash
{
"commit": "unknown",
Expand All @@ -72,6 +74,7 @@ In a separate console run `curl localhost:8008/version`. You should see similar
### go-slalom server

The `start` command (in cmd package) calls

```go
api.NewServer().ListenAndServe()
```
Expand All @@ -86,5 +89,8 @@ See `pkg/api/server.go`. It does the following:
- disable probes to tell kubernetes it is unavailable
- gracefully shutdown server

## Next

[Deploy go-slalom with skaffold](skaffold-go-slalom.md)

![gopher-head](images/gopher_head.png)
68 changes: 68 additions & 0 deletions docs/configmaps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Configmaps

Configmaps are a simple, but vital object in kubernetes. Most applications will use configmaps for configuration

## go-slalom configmap

The go-slalom configmap is configured in [deploy/skaffold/configmap.yaml](../deploy/skaffold/configmap.yaml)

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: go-slalom
data:
# property-like keys; each key maps to a simple value
magic_value: "TODO"
```

We can also see it using kubectl commands

```bash
# list configmaps
kubectl get configmaps

# show go-slalom configmap
kubectl get configmap go-slalom -o yaml
```

The "magic_value" is mapped as environment variable "MAGIC_VALUE" in [deploy/skaffold/deployment.yaml](../deploy/skaffold/deployment.yaml)

```yaml
env:
- name: MAGIC_VALUE
valueFrom:
configMapKeyRef:
name: go-slalom
key: magic_value
```

The environment variable value is used in the output of the service

## Editing Configmaps

You can see there is only 1 field, magic_value, that is set to "TODO". Let's change it

```bash
kubectl edit configmap go-slalom
```

Now curl go-slalom again...

What! It is still showing "TODO" for "magic_value". That is expected... the pod needs restarted so it can receive the new value.

We could restart skaffold, or another way is to disable the healthcheck and let kubernetes restart the pod:

```bash
curl -X POST localhost:8080/health/disable
```

After a moment you will see kubernetes sends a signal to tell the pod to shutdown. The pod handles the signal and exits. Kubernetes starts a new pod.

Now if we curl the service again we will see the updated configmap value in the result

## Next

[Release go-slalom](go-releaser.md)

![slalom-gopher](images/gopher-mic-drop.png)
8 changes: 7 additions & 1 deletion docs/go-101.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,10 @@ slice = array[:]
- <https://golang.org/ref/spec> learn more about the language itself
- <https://golang.org/doc/#articles> a lot more reading material
- <https://golang.org/doc/editors.html> editor plugins for go
- <https://www.jetbrains.com/go/> Goland IDE from JetBrains
- <https://www.jetbrains.com/go/> Goland IDE from JetBrains

## Next

[Hello World in Go](go-hello-world.md)

![pirate gopher](images/pirate-gopher.png)
22 changes: 15 additions & 7 deletions docs/go-hello-world.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Go Hello World
# Go Hello World

Create a working web app with the code below!

Expand All @@ -21,7 +21,7 @@ func main() {
}
```

### Steps
## Steps

- create a `hello.go` file using below

Expand All @@ -45,31 +45,39 @@ func main() {
```

- run the following command and leave console open

```bash
go run hello.go
```

- in browser go to (replace YOUR_NAME with your name) `http://localhost:8080/YOUR_NAME` or in separate console

```bash
open http://localhost:8080/$USER
```

![hello](screens/hello-screen.png)

## Awesomeness!
## Awesomeness

So what did you do? When you ran `go run hello.go`, go compiled hello.go, created a binary in a temporary folder, and ran it.

Alternatively you could build and run it with
Alternatively you could build and run it with

```bash
go build hello.go
./hello
```

In above, go compiled hello.go and created a binary in current path. You then can run it.

### compiled server

In many other languages you need to deploy your app to a web app server or "bundle" a server with your app. With go the
server is built and compiled into your app (binary).
In many other languages you need to deploy your app to a web app server or "bundle" a server with your app. With go the server is built and compiled into your app (binary).

## Next

[Run go-slalom](build-go-slalom.md)

![gopher ninja](images/gopher-ninja.png)

![gopher ninja](images/gopher-ninja.png)
19 changes: 13 additions & 6 deletions docs/go-releaser.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Release go-slalom

If you are working on a cli or application that you want to make available to your team or otherwise then you will want
to create a github release and provide binaries.
to create a github release and provide binaries.

Or you may want to create a release for your service with binaries and use those when creating an image.

Below will show you how to use [goreleaser](https://goreleaser.com) to release a go application. What does goreleaser do?

>GoReleaser builds Go binaries for several platforms, creates a GitHub release and then pushes a Homebrew formula to a
tap repository. All that wrapped in your favorite CI.
> GoReleaser builds Go binaries for several platforms, creates a GitHub release and then pushes a Homebrew formula to a
> tap repository. All that wrapped in your favorite CI.

### Use goreleaser
## Use goreleaser

First install goreleaser

Expand All @@ -26,7 +26,8 @@ export GITHUB_TOKEN=`YOUR_TOKEN`

It uses the latest tag applied to your repository. Create a tag if one does not exist

**Note**, the tag must adhere to [semantic versioning](https://goreleaser.com/semver).
**Note**, the tag must adhere to [semantic versioning](https://goreleaser.com/semver).

```bash
$ git tag -a v0.1.0 -m "First release"
$ git push origin v0.1.0
Expand All @@ -39,6 +40,7 @@ You will also need to create a git repository for homebrew tap
- change the `brew.github.owner` value in [.goreleaser.yml](../.goreleaser.yml) to your github handle.

Now run goreleaser!

```bash
goreleaser
```
Expand All @@ -55,6 +57,7 @@ brew install go-slalom
```

You should see similar output

```bash
==> Installing tredfield/tap/go-slalom
==> Downloading https://github.com/tredfield/go-slalom/releases/download/v0.0.1/go-slalom_0.0.1_Darwin_x86_64.tar.gz
Expand All @@ -63,4 +66,8 @@ You should see similar output
/usr/local/Cellar/go-slalom/0.0.1: 4 files, 10MB, built in 6 seconds
```

![go-cloud](images/gopher-cloud.png)
## Next

[What's Next?](whats-next.md)

![go-cloud](images/gopher-cloud.png)
Binary file modified docs/images/go-n-docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/gopher-mic-drop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/k8s-and-gopher-ocean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/k8s-boat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/kubernetes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/pirate-gopher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading