Skip to content

Commit

Permalink
update the example according to the latest template (KusionStack#174)
Browse files Browse the repository at this point in the history
* update the example according to the latest template

* separate shell commands to copy easily
  • Loading branch information
SparkYuan authored Oct 30, 2022
1 parent ee40fb1 commit 6d64581
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 37 deletions.
59 changes: 41 additions & 18 deletions docs/user_docs/getting-started/usecase.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ This tutorial will demonstrate how to deliver an App with a Loadbalancer in one

## Init Project

Firstly, clone the Konfig repo and enter the root directory:
Firstly, let's clone the Konfig repo and enter the root directory:

```bash
```shell
git clone git@github.com:KusionStack/konfig.git && cd konfig
```

Let's init this tutorial project with `kusion init --online`
```bash
After this step, we can init this tutorial project with online templates
```shell
kusion init --online
```

All init templates are listed as follows:

```shell
➜ konfig git:(main) ✗ kusion init --online
? Please choose a template: [Use arrows to move, type to filter]
> code-city Code City metaphor for visualizing Go source code in 3D.
Expand All @@ -32,12 +38,13 @@ Select `code-city` and press `Enter`. After that, we will see hints below and us
![](/img/docs/user_docs/getting-started/choose-template.gif)
The whole file hierarchy is shown below. More details about the directory structure can be found in
[Konfig](/docs/user_docs/concepts/konfig).
After this process, we can get the whole file hierarchy with this command
```shell
cd code-city && tree
```
```shell
➜ konfig git:(main) ✗ cd code-city
➜ code-city git:(main) ✗ tree
➜ konfig git:(main) ✗ cd code-city && tree
.
├── base
│   └── base.k
Expand All @@ -51,35 +58,51 @@ The whole file hierarchy is shown below. More details about the directory struct

3 directories, 6 files
```
More details about the directory structure can be found in
[Konfig](/docs/user_docs/concepts/konfig).
### Review Config Files
```python
# main.k
import .pkg
import base.pkg.kusion_models.kube.frontend

app = pkg.App {
# The application configuration in stack will overwrite
# the configuration with the same attribute in base.
appConfiguration: frontend.Server {
image = "howieyuen/gocity:latest"
}
```
`main.k` only contains 5 lines (including an empty line). Line 1 imports a pkg that contains the model `App` which is an abstract model representing the App we will deliver later. This model hides the complexity of Kubernetes `Deployment` and `Service` and only one field `image` is needed to make this App ready to use.
`main.k` only contains 4 lines. Line 1 imports a pkg that contains the model `Server` which is an abstract model representing the App we will deliver later. This model hides the complexity of Kubernetes `Deployment` and `Service` and only one field `image` is needed to make this App ready to use.
More details about Konfig Models can be found in [Konfig](https://github.com/KusionStack/konfig)
## Delivery
Deliver this App into a Kubernetes cluster with one command `kusion apply`
```shell
cd dev && kusion apply --watch
```
Go to the `dev` folder and we will deliver this App into a Kubernetes cluster with one command `kusion apply --watch`
![](/img/docs/user_docs/getting-started/apply.gif)
Check `Deploy` status.
Check `Deploy` status
```shell
➜ examples git:(main) ✗ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
gocity 1/1 1 1 1m
kubectl -ncode-city get deploy
```
The expected output is shown as follows:
Port-forward our App
```shell
➜ examples git:(main) ✗ kubectl port-forward svc/gocity 4000:4000
➜ dev git:(main) ✗ kubectl -ncode-city get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
code-citydev 1/1 1 1 1m
```
Port-forward our App with the `service`
```shell
kubectl port-forward -ncode-city svc/gocity 4000:4000
```
```shell
➜ dev git:(main) ✗ kubectl port-forward -ncode-city svc/gocity 4000:4000
Forwarding from 127.0.0.1:4000 -> 4000
Forwarding from [::1]:4000 -> 4000
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ This tutorial will demonstrate how to deliver an App with a Loadbalancer in one

## Init Project

Firstly, clone the Konfig repo and enter the root directory:
Firstly, let's clone the Konfig repo and enter the root directory:

```bash
```shell
git clone git@github.com:KusionStack/konfig.git && cd konfig
```

Let's init this tutorial project with `kusion init --online`
```bash
After this step, we can init this tutorial project with online templates
```shell
kusion init --online
```

All init templates are listed as follows:

```shell
➜ konfig git:(main) ✗ kusion init --online
? Please choose a template: [Use arrows to move, type to filter]
> code-city Code City metaphor for visualizing Go source code in 3D.
Expand All @@ -32,12 +38,13 @@ Select `code-city` and press `Enter`. After that, we will see hints below and us
![](/img/docs/user_docs/getting-started/choose-template.gif)
The whole file hierarchy is shown below. More details about the directory structure can be found in
[Konfig](/docs/user_docs/concepts/konfig).
After this process, we can get the whole file hierarchy with this command
```shell
cd code-city && tree
```
```shell
➜ konfig git:(main) ✗ cd code-city
➜ code-city git:(main) ✗ tree
➜ konfig git:(main) ✗ cd code-city && tree
.
├── base
│   └── base.k
Expand All @@ -51,35 +58,51 @@ The whole file hierarchy is shown below. More details about the directory struct

3 directories, 6 files
```
More details about the directory structure can be found in
[Konfig](/docs/user_docs/concepts/konfig).
### Review Config Files
```python
# main.k
import .pkg
import base.pkg.kusion_models.kube.frontend

app = pkg.App {
image = "yuanhao1223/gocity:latest"
# The application configuration in stack will overwrite
# the configuration with the same attribute in base.
appConfiguration: frontend.Server {
image = "howieyuen/gocity:latest"
}
```
`main.k` only contains 5 lines (including an empty line). Line 1 imports a pkg that contains the model `App` which is an abstract model representing the App we will deliver later. This model hides the complexity of Kubernetes `Deployment` and `Service` and only one field `image` is needed to make this App ready to use.
`main.k` only contains 4 lines. Line 1 imports a pkg that contains the model `Server` which is an abstract model representing the App we will deliver later. This model hides the complexity of Kubernetes `Deployment` and `Service` and only one field `image` is needed to make this App ready to use.
More details about Konfig Models can be found in [Konfig](https://github.com/KusionStack/konfig)
## Delivery
Deliver this App into a Kubernetes cluster with one command `kusion apply`
```shell
cd dev && kusion apply --watch
```
Go to the `dev` folder and we will deliver this App into a Kubernetes cluster with one command `kusion apply --watch`
![](/img/docs/user_docs/getting-started/apply.gif)
Check `Deploy` status.
Check `Deploy` status
```shell
➜ examples git:(main) ✗ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
gocity 1/1 1 1 1m
kubectl -ncode-city get deploy
```
The expected output is shown as follows:
Port-forward our App
```shell
➜ examples git:(main) ✗ kubectl port-forward svc/gocity 4000:4000
➜ dev git:(main) ✗ kubectl -ncode-city get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
code-citydev 1/1 1 1 1m
```
Port-forward our App with the `service`
```shell
kubectl port-forward -ncode-city svc/gocity 4000:4000
```
```shell
➜ dev git:(main) ✗ kubectl port-forward -ncode-city svc/gocity 4000:4000
Forwarding from 127.0.0.1:4000 -> 4000
Forwarding from [::1]:4000 -> 4000
```
Expand Down

0 comments on commit 6d64581

Please sign in to comment.