Skip to content

Commit

Permalink
OVHCloud Managed Kubernetes example (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
yodamad committed Apr 8, 2024
1 parent 6b19450 commit 2f3ac94
Show file tree
Hide file tree
Showing 8 changed files with 659 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Don't see an example listed? [Try Pulumi AI](https://www.pulumi.com/ai) and use
- [Go](#go-3)
- [C#](#c-3)
- [Openstack](#openstack)
- [OVHCloud](#ovhcloud)
- [Cloud](#cloud)
- [DigitalOcean](#digitalocean)
- [Multicloud](#multicloud)
Expand Down Expand Up @@ -358,6 +359,14 @@ Example | Description |

[Web Server](openstack-py-webserver) | Deploy an Openstack instance and open port 8000.

## OVHCloud

### Go

| Example | Description |
|--------------------------------------| --------- |
| [Kubernetes](ovhcloud-go-kubernetes) | A sample to deploy a managed Kubernetes cluster on OVHcloud |

## Cloud

### TypeScript
Expand Down
14 changes: 14 additions & 0 deletions ovhcloud-go-kubernetes/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: ovhcloud-kubernetes
runtime: go
description: A Go program to deploy a Kubernetes cluster on OVHcloud
config:
# Cluster info
k8s_enabled: true
cluster:flavor: d2-4
cluster:name: pulumi-cluster
cluster:nodepool: pulumi-pool
cluster:min_nodes: 1
cluster:max_nodes: 2
cluster:region: GRA9
# OVH info
ovh:endpoint: ovh-eu
110 changes: 110 additions & 0 deletions ovhcloud-go-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Managed Kubernetes on OVH

## Prerequisites

You need to setup some environment variables to use this template

```bash
# Your OVH project ID
export OVH_SERVICE_NAME=xxx
# Your application information (can be on https://api.ovh.com/createToken)
export OVH_APPLICATION_SECRET=xxx
export OVH_APPLICATION_KEY=xxx
export OVH_CONSUMER_KEY=xxx
```

## Configuration

You can easily configure your setup in `Pulumi.yaml`

| Key | Description | Default value |
|-------------------|----------------------------------------------|---|
| cluster:flavor | Default size for cluster nodes | d2-4 |
| cluster:name | Cluster name | pulumi-cluster |
| cluster:nodepool | Nodepool name | pulumi-pool |
| cluster:min_nodes | Minimum nb of nodes in cluster | 1 |
| cluster:max_nodes | Minimum nb of nodes in cluster | 2 |
| cluster:region | Datacenter in which cluster will be deployed | GRA9 |
| ovh:endpoint | Endpoint for OVH APIs | ovh-eu |

## Usage sample

### Initialization

If you haven't already, follow the steps in [Pulumi Installation and Setup](https://www.pulumi.com/docs/get-started/install/) and [Configuring Pulumi Kubernetes](https://www.pulumi.com/docs/intro/cloud-providers/kubernetes/setup/) to get set up with Pulumi and Kubernetes.

Then, run command to install go dependencies:

```sh
go mod download
````

### pulumi init

If no stack initialized, run the classic `pulumi stack init` command first

### pulumi preview

```console
$ pulumi preview
Please choose a stack, or create a new one: gitpod
Previewing update (gitpod)
View in Browser (Ctrl+O): https://app.pulumi.com/yodamad/hashnode-article/gitpod/previews/xxx
Type Name Plan
+ pulumi:pulumi:Stack hashnode-article-gitpod create
+ ├─ ovh:CloudProject:Kube pulumi-cluster create
+ └─ ovh:CloudProject:KubeNodePool pulumi-pool create
Outputs:
kubeconfig: output<string>
Resources:
+ 3 to create
```

### pulumi up

```console
$ pulumi up
Please choose a stack, or create a new one: gitpod
Previewing update (gitpod)
View in Browser (Ctrl+O): https://app.pulumi.com/yodamad/hashnode-article/gitpod/previews/xxx
Type Name Plan
+ pulumi:pulumi:Stack hashnode-article-gitpod create
+ ├─ ovh:CloudProject:Kube pulumi-cluster create
+ └─ ovh:CloudProject:KubeNodePool pulumi-pool create
Outputs:
kubeconfig: output<string>
Resources:
+ 3 to create
Do you want to perform this update? yes
Updating (gitpod)
View in Browser (Ctrl+O): https://app.pulumi.com/xxx/xxx/gitpod/updates/1
Type Name Status
+ pulumi:pulumi:Stack hashnode-article-gitpod created (405s)
+ ├─ ovh:CloudProject:Kube pulumi-cluster created (401s)
+ └─ ovh:CloudProject:KubeNodePool pulumi-pool created (222s)
Outputs:
kubeconfig: [secret]
Resources:
+ 3 created
Duration: 10m30s
```

### Retrieve `kubeconfig``

```bash
pulumi stack output kubeconfig --show-secrets > kubeconfig
``````
34 changes: 34 additions & 0 deletions ovhcloud-go-kubernetes/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

const OvhApplicationKey = "OVH_APPLICATION_KEY"
const OvhApplicationSecret = "OVH_APPLICATION_SECRET"
const OvhConsumerKey = "OVH_CONSUMER_KEY"
const OvhServiceName = "OVH_SERVICE_NAME"
const OvhGroup = "ovh"
const FLAVOR = "flavor"
const REGION = "region"

func ovhConfig(ctx *pulumi.Context, key string) string {
return getConfig(ctx, OvhGroup, key)
}

// Cluster config keys
const ClusterGroup = "cluster"
const NAME = "name"
const NodePool = "nodepool"
const MinNodes = "min_nodes"
const MaxNodes = "max_nodes"

func clusterConfig(ctx *pulumi.Context, key string) string {
return getConfig(ctx, ClusterGroup, key)
}

func getConfig(ctx *pulumi.Context, group string, key string) string {
return config.Require(ctx, fmt.Sprintf("%s:%s", group, key))
}
93 changes: 93 additions & 0 deletions ovhcloud-go-kubernetes/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module ovhcloud-go-kubernetes

go 1.22

require (
github.com/ovh/pulumi-ovh/sdk v0.40.1
github.com/pulumi/pulumi/sdk/v3 v3.112.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/charmbracelet/bubbles v0.16.1 // indirect
github.com/charmbracelet/bubbletea v0.24.2 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/djherbis/times v1.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl/v2 v2.17.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.6.2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
)
Loading

0 comments on commit 2f3ac94

Please sign in to comment.