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

Install knative #177

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions knative/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
template
build
.secrets
40 changes: 40 additions & 0 deletions knative/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# What is Knative?

A way to deploy FaaS objects into Kubernetes

## How to get started

Install the CLI

```bash
brew tap knative-sandbox/kn-plugins
brew install func
```

To deploy a Knative function, use a yaml like the following:

```yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: hello
spec:
template:
spec:
containers:
- image: ghcr.io/knative/helloworld-go:latest # Container to be used
ports:
- containerPort: 8080
env:
- name: TARGET # Env vars
value: "World"
```

The lifecycle of building and deploying the image used as the service
is described [here](https://knative.dev/docs/getting-started/create-a-function/)

e.g. the following will create a folder with a python function in it

```bash
func create -l python hello
```
17 changes: 17 additions & 0 deletions knative/dev/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-dev-terraform"
key = "terraform-knative.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions knative/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "knative" {
source = "../knative_k8s"
cluster_name = "dev-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions knative/dev/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
10 changes: 10 additions & 0 deletions knative/knative_k8s/knative_eventing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Namespace
metadata:
name: knative-eventing
---
apiVersion: operator.knative.dev/v1beta1
kind: KnativeEventing
metadata:
name: knative-eventing
namespace: knative-eventing
10 changes: 10 additions & 0 deletions knative/knative_k8s/knative_serving.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Namespace
metadata:
name: knative-serving
---
apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
name: knative-serving
namespace: knative-serving
58 changes: 58 additions & 0 deletions knative/knative_k8s/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
data "digitalocean_kubernetes_cluster" "dev" {
name = var.cluster_name
}


provider "kubernetes" {
host = data.digitalocean_kubernetes_cluster.dev.endpoint
token = data.digitalocean_kubernetes_cluster.dev.kube_config[0].token
cluster_ca_certificate = base64decode(
data.digitalocean_kubernetes_cluster.dev.kube_config[0].cluster_ca_certificate
)
}

provider "kubectl" {
host = data.digitalocean_kubernetes_cluster.dev.endpoint
token = data.digitalocean_kubernetes_cluster.dev.kube_config[0].token
cluster_ca_certificate = base64decode(
data.digitalocean_kubernetes_cluster.dev.kube_config[0].cluster_ca_certificate
)
}

data "http" "knative_operator_yaml" {
url = "https://github.com/knative/operator/releases/download/knative-v1.10.2/operator.yaml"

# Optional request headers
request_headers = {
Accept = "application/yaml"
}
}

data "kubectl_file_documents" "docs" {
content = tostring(data.http.knative_operator_yaml.body)
}

resource "kubectl_manifest" "knative_operator" {
for_each = data.kubectl_file_documents.docs.manifests
yaml_body = each.value
}

data "kubectl_file_documents" "serving_docs" {
content = file("${path.module}/knative_serving.yaml")
}

resource "kubectl_manifest" "knative_serving" {
for_each = data.kubectl_file_documents.serving_docs.manifests
yaml_body = each.value
}



data "kubectl_file_documents" "eventing_docs" {
content = file("${path.module}/knative_eventing.yaml")
}

resource "kubectl_manifest" "knative_eventing" {
for_each = data.kubectl_file_documents.eventing_docs.manifests
yaml_body = each.value
}
13 changes: 13 additions & 0 deletions knative/knative_k8s/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
kubectl = {
source = "gavinbunney/kubectl"
version = "1.14.0"
}
}
}
3 changes: 3 additions & 0 deletions knative/knative_k8s/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "cluster_name" {
type = string
}
17 changes: 17 additions & 0 deletions knative/prod/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-production-terraform"
key = "terraform-knative.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions knative/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "knative" {
source = "../knative_k8s"
cluster_name = "prod-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions knative/prod/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}
17 changes: 17 additions & 0 deletions knative/test/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

terraform {
# DigitalOcean uses the S3 spec.
backend "s3" {
bucket = "treetracker-test-terraform"
key = "terraform-knative.tfstate"
endpoint = "https://sfo2.digitaloceanspaces.com"
# DO uses the S3 format
# eu-west-1 is used to pass TF validation
# Region is ACTUALLY sfo2 on DO
region = "eu-west-1"
# Deactivate a few checks as TF will attempt these against AWS
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
4 changes: 4 additions & 0 deletions knative/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "knative" {
source = "../knative_k8s"
cluster_name = "test-k8s-treetracker"
}
10 changes: 10 additions & 0 deletions knative/test/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.28.1"
}
kubernetes = "2.16.1"
helm = "2.8.0"
}
}