Skip to content

Kind #3

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

Open
wants to merge 6 commits into
base: main
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
21 changes: 21 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# schedule-nginx-deployment
# deploy-nginx
deploy nginx will deploy surprisingly four replicas of nginx on kind cluster with k8s deployment

## Setup
These enviroment variables are required:

- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY

Create local kind cluster:

```
brew install kind
kind create cluster --name nginx --config kind-config.yaml
kind get clusters
kubectl cluster-info --context kind-nginx
```

You need to get cluster configurations from ```~/.kube/config``` and apply it on ```terraform.tfvars``` then you can run:

```
terraform init
```

## Deploy
```
terraform apply
```

## Destroy
```
terraform destroy
```
8 changes: 8 additions & 0 deletions kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30201
hostPort: 30201
listenAddress: "0.0.0.0"
95 changes: 95 additions & 0 deletions kubernetes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
}
}
}

variable "host" {
type = string
}

variable "client_certificate" {
type = string
}

variable "client_key" {
type = string
}

variable "cluster_ca_certificate" {
type = string
}

provider "kubernetes" {
host = var.host

client_certificate = base64decode(var.client_certificate)
client_key = base64decode(var.client_key)
cluster_ca_certificate = base64decode(var.cluster_ca_certificate)
}

resource "kubernetes_deployment" "nginx" {
metadata {
name = "nginx"
labels = {
App = "Nginx"
}
}

spec {
replicas = 4
selector {
match_labels = {
App = "Nginx"
}
}
template {
metadata {
labels = {
App = "Nginx"
}
}
spec {
container {
image = "nginx:1.7.8"
name = "nginx"

port {
container_port = 80
}

resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
}
}
}
}
}

resource "kubernetes_service" "nginx" {
metadata {
name = "nginx"
}
spec {
selector = {
App = kubernetes_deployment.nginx.spec.0.template.0.metadata[0].labels.App
}
port {
node_port = 30201
port = 80
target_port = 80
}

type = "NodePort"
}
}
4 changes: 4 additions & 0 deletions terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
host = ""
client_certificate = ""
client_key = ""
cluster_ca_certificate = ""