Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(website): getting started revamp #1285

Merged
merged 59 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
8269728
update: clean-up docs and add check version
tucktuck9 Apr 18, 2023
9acd66c
create: initial dir structure and python guide
tucktuck9 Apr 18, 2023
2712a68
update: python class name
tucktuck9 Apr 18, 2023
576c0fe
edits: minor tweaks and clean-up
tucktuck9 Apr 18, 2023
965ae05
update: add links for each install option
tucktuck9 Apr 21, 2023
d13b2fa
edits: incorporate feedback
tucktuck9 Apr 21, 2023
abf3b1e
update: python specific conventions and sample
tucktuck9 Apr 23, 2023
85d72cb
update: kubernetes manifest example
tucktuck9 Apr 23, 2023
8083995
Merge branch 'master' into language-gs
iliapolo Jun 20, 2023
782c484
update: code samples
tucktuck9 Jul 11, 2023
becf7a5
update: incorporate edits and add conclusion
tucktuck9 Jul 11, 2023
37496dd
update: edit cdk8s lower case
tucktuck9 Jul 11, 2023
9a6b1ac
edits: cdk8s lower case
tucktuck9 Jul 11, 2023
05d937a
updates: incorporate numerous edits
tucktuck9 Jul 11, 2023
473d11f
edits: minor tweaks to language
tucktuck9 Jul 11, 2023
7447d93
update: emphasize pythonic conventions
tucktuck9 Jul 11, 2023
8a63711
update: change headings to present tense
tucktuck9 Jul 11, 2023
408874c
edits: incorporate feedback and minor tweaks
tucktuck9 Jul 11, 2023
0f325df
update: class name to MyChart
tucktuck9 Jul 11, 2023
b043eba
update: add npm to prereqs
tucktuck9 Jul 11, 2023
0dfb1e0
update: init method pythonic language
tucktuck9 Jul 11, 2023
8ffcfe6
Merge branch 'master' into language-gs
iliapolo Jul 25, 2023
eb98bf0
update: last tweaks from feedback
tucktuck9 Jul 25, 2023
46a92d3
create: structure for typescript guide
tucktuck9 Aug 8, 2023
3763d62
create: structure for java guide
tucktuck9 Aug 8, 2023
acb8b1b
create: structure for go guide
tucktuck9 Aug 8, 2023
82d0c81
update: incorporate feedback to go and typescript
tucktuck9 Aug 8, 2023
6e631c6
create: typescript guide
tucktuck9 Aug 30, 2023
b1cd3bf
update: add typescript conclusion
tucktuck9 Aug 30, 2023
a7156ad
add: java guide
tucktuck9 Aug 30, 2023
96e1165
update: tweaks to file name and heading
tucktuck9 Aug 30, 2023
4d58bf4
add: section description for code sample
tucktuck9 Aug 30, 2023
489874b
update: incorporate java feedback
tucktuck9 Sep 13, 2023
07bb1bc
update: incorporate go feedback
tucktuck9 Sep 13, 2023
99f0394
update: remove go modules links
tucktuck9 Sep 13, 2023
96ced19
update: complete go guide and code
tucktuck9 Sep 19, 2023
aff72ff
Merge branch 'master' into language-gs
iliapolo Sep 27, 2023
4d468c2
Update docs/get-started/python.md
iliapolo Sep 27, 2023
8b1c574
Update docs/get-started/typescript.md
iliapolo Sep 27, 2023
592c0cc
Update docs/get-started/.pages
iliapolo Sep 27, 2023
f777aa6
Update docs/get-started/go.md
iliapolo Sep 27, 2023
596d704
Update docs/get-started/java.md
iliapolo Sep 27, 2023
65f4986
Update docs/get-started/python.md
iliapolo Sep 27, 2023
a4300bb
Update docs/get-started/typescript.md
iliapolo Sep 27, 2023
746e188
Update docs/get-started/index.md
iliapolo Sep 27, 2023
85b0195
Update docs/get-started/.pages
iliapolo Sep 27, 2023
e95fe84
Update docs/get-started/go.md
iliapolo Sep 27, 2023
c21282e
Update docs/get-started/java.md
iliapolo Sep 27, 2023
a5da509
Update docs/get-started/python.md
iliapolo Sep 27, 2023
0078ad4
Update docs/get-started/typescript.md
iliapolo Sep 27, 2023
a0a9578
update: code format
tucktuck9 Sep 27, 2023
1953b16
update: remove go mod steps
tucktuck9 Sep 27, 2023
d9ed7bb
Merge branch 'master' into language-gs
iliapolo Oct 16, 2023
efe163d
Update docs/get-started/go.md
iliapolo Oct 17, 2023
5c28e9c
Update docs/get-started/go.md
iliapolo Oct 17, 2023
73951b0
Update docs/get-started/go.md
iliapolo Oct 17, 2023
075c848
Update docs/get-started/go.md
iliapolo Oct 17, 2023
9113025
Apply suggestions from code review
iliapolo Oct 17, 2023
bbe8485
Merge branch 'master' into language-gs
iliapolo Oct 17, 2023
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
2 changes: 1 addition & 1 deletion docs/.pages
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nav:
- What is cdk8s?: index.md
- getting-started.md
- Getting started: get-started
- basics
- cdk8s+: plus
- CLI: cli
Expand Down
36 changes: 28 additions & 8 deletions docs/cli/installation.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
# Installation
# Install the cdk8s CLI

To install the CLI use one of the following methods:
This page describes the different ways you can install the Cloud Development Kit for Kubernetes (cdk8s) command-line interface (CLI) tool on your local machine.

=== "npm"
`npm i -g cdk8s-cli`
## Installation
### Homebrew
To install the cdk8s CLI with [Homebrew](https://brew.sh/), run the following command:
```console
brew install cdk8s
```

=== "yarn"
`yarn global add cdk8s-cli`
### npm
To install the cdk8s CLI with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), run the following command:
```console
npm i -g cdk8s-cli
```

=== "Homebrew"
`brew install cdk8s`
### Yarn
To install the cdk8s CLI with [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable), run the following command:
```console
yarn global add cdk8s-cli
```

## Check version
To check your version, run the following command:
```console
cdk8s --version
```
You should see something similar to the following:
```
2.2.31
```
6 changes: 6 additions & 0 deletions docs/get-started/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
nav:
- index.md
- Python: python.md
- TypeScript: typescript.md
- Java: java.md
- Go: go.md
177 changes: 177 additions & 0 deletions docs/get-started/go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Getting started with cdk8s for Go
In this guide, we'll walk you through the process of building a basic Kubernetes application using cdk8s for Go.

## Prerequisites
1. To install the cdk8s CLI, you need the [Node Package Manager (npm)](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) installed on your local machine.
2. cdk8s for Go supports Go versions 1.16+. Check your Go version:
```bash
go version
```

## Set up an environment
### Install the CLI
To initialize a cdk8s project and auto-generate Kubernetes manifests based on our code, we need the cdk8s CLI:

1. Run the following command to install the CLI using [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm). For more installation methods, see [Install the cdk8s CLI](./../cli/installation.md).
```console
npm install -g cdk8s-cli
```

### Create a project
Next, we’ll initialize a project to create the directory structure and install the necessary dependencies using the [init](./../cli/init.md) command.

1. In a terminal window, create a new directory:
```bash
mkdir cdk8s-golang
```

2. Next, run the following command inside the `cdk8s-golang` directory:
```console
cdk8s init go-app
```

3. In your preferred code editor, open the `main.go` file.
```go
package main

import (
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
"github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2"
)

type MyChartProps struct {
cdk8s.ChartProps
}

func NewMyChart(scope constructs.Construct, id string, props *MyChartProps) cdk8s.Chart {
var cprops cdk8s.ChartProps
if props != nil {
cprops = props.ChartProps
}
chart := cdk8s.NewChart(scope, jsii.String(id), &cprops)

// define resources here

return chart
}

func main() {
app := cdk8s.NewApp(nil)
NewMyChart(app, "cdk8s-golang", nil)
app.Synth()
}
```

This sample shows the basic structure of a cdk8s application with the essential libraries: **constructs** and **cdk8s**. These libraries supply the foundational classes and methods required for working with cdk8s. It includes the following components:

* A `NewMyChart` function that creates a specific instance of a [Chart](https://pkg.go.dev/github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2#Chart). It is responsible for initializing the Chart instance and registering the Kubernetes resources to it.
* A `main` function acting as the primary entry point of the cdk8s application. It instantiates the [App](https://pkg.go.dev/github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2#App) instance, which oversees the application's lifecycle and resources.
* The function `NewMyChart` is called by passing the app instance and a string identifier, "go", as arguments. This action generates and registers the chart and all its resources to the app. Note that in this example, the "go" string identifier is autogenerated based on the current directory name.
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
* The `synth` method is called on the `app` instance, which produces the required Kubernetes YAML manifest files based on the defined resources. Note that in this example, we haven't defined any resources within the `NewMyChart` function, so running the "cdk8s synth" command in the CLI would generate a blank Kubernetes manifest.
iliapolo marked this conversation as resolved.
Show resolved Hide resolved

## Define Kubernetes resources
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
Now, let's delve into defining Kubernetes resources for our application. In this example, we'll outline a basic Kubernetes [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) for a sample app. We'll start by importing the `imports` directory and the `k8s` sub-directory, which houses all cdk8s Kubernetes classes and functions.

### Copy the code sample
iliapolo marked this conversation as resolved.
Show resolved Hide resolved

1. Copy and paste the following code sample into the existing `main.go` file of your project.

```typescript
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
package main

import (
"example.com/cdk8s-golang/imports/k8s"
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
"github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2"
)

func NewChart(scope constructs.Construct, id string, ns string, appLabel string) cdk8s.Chart {

chart := cdk8s.NewChart(scope, jsii.String(id), &cdk8s.ChartProps{
Namespace: jsii.String(ns),
})

labels := map[string]*string{
"app": jsii.String(appLabel),
}

k8s.NewKubeDeployment(chart, jsii.String("deployment"), &k8s.KubeDeploymentProps{
Spec: &k8s.DeploymentSpec{
Replicas: jsii.Number(3),
Selector: &k8s.LabelSelector{
MatchLabels: &labels,
},
Template: &k8s.PodTemplateSpec{
Metadata: &k8s.ObjectMeta{
Labels: &labels,
},
Spec: &k8s.PodSpec{
Containers: &[]*k8s.Container{{
Name: jsii.String("app-container"),
Image: jsii.String("nginx:1.19.10"),
Ports: &[]*k8s.ContainerPort{{
ContainerPort: jsii.Number(80),
}},
}},
},
},
},
})

return chart
}

func main() {
app := cdk8s.NewApp(nil)

NewChart(app, "getting-started", "default", "my-app")

app.Synth()
}
```
iliapolo marked this conversation as resolved.
Show resolved Hide resolved

A few things worth noting about this sample:

- The `NewChart` function utilizes Go's strong typing and interface-based design to construct a Kubernetes Deployment. This Deployment is set up with specific parameters like replica count, label selectors, and pod specifications. This method takes advantage of Go's map data structures to dynamically assign the "app" key in label selectors and metadata labels, offering a straightforward and efficient way to configure essential details.

## Generate Kubernetes manifests
After you have defined the Kubernetes resources for your application, you are ready to generate the Kubernetes manifest that will define your Deployment resource.

### Run the synth command
1. Open a terminal and navigate to your project directory.
2. Run the [synth](https://cdk8s.io/docs/latest/cli/synth/) command. This command generates a Kubernetes manifest file in the `dist` folder of your project directory. The manifest file contains all the resources you defined inside the `MyChart` class.
```console
cdk8s synth
```

### View the manifest
1. Open the `dist/getting-started.k8s.yaml` file. You should see a Kubernetes manifest similar to the following:
```bash
apiVersion: apps/v1
kind: Deployment
metadata:
name: getting-started-deployment-c80c7257
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- image: nginx:1.19.10
name: app-container
ports:
- containerPort: 80
```
## Conclusion
Throughout this guide, we introduced you to the cdk8s Go library and guided you through the process of creating a cdk8s Go application. We initiated a simple project and constructed a Kubernetes Deployment using cdk8s code. This included leveraging Go-specific programming language conventions to dynamically set the "app" key in "label" selectors and "metadata" labels for Kubernetes resources using Go's versatile handling of map data structures.

## Next up
- To run a complete code sample, we recommend diving into the Kubernetes [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) and [Service](https://kubernetes.io/docs/concepts/services-networking/service/) using the [cdk8s-core](https://github.com/cdk8s-team/cdk8s-examples/blob/main/go/cdk8s-core/main.go) sample application.
8 changes: 8 additions & 0 deletions docs/get-started/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Getting started
CDK8s streamlines the automation of deployment, versioning, and configuration for your Kubernetes resources, so you can build and upgrade your clusters more easily. Whether you're creating new applications, managing microservices, or working with data processing pipelines, cdk8s has you covered. To kick start your journey, choose one of our language guides tailored to your preferred programming language.

### Choose a language guide
- [Python](python.md)
- [Typescript](typescript.md)
- [Java](java.md)
- [Go](go.md)
Loading