-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from hashmap-kz/doc/examples
examples - add examples with basic usage
- Loading branch information
Showing
17 changed files
with
304 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
integration/immutable_data/** linguist-vendored | ||
testdata/** linguist-vendored | ||
examples/** linguist-vendored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# prepare config for the 'kind' cluster | ||
cat <<EOF >kind-config.yaml | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
name: "kubectl-envsubst" | ||
nodes: | ||
- role: control-plane | ||
extraPortMappings: | ||
- containerPort: 32501 | ||
hostPort: 32501 | ||
protocol: TCP | ||
- containerPort: 32502 | ||
hostPort: 32502 | ||
protocol: TCP | ||
- containerPort: 32503 | ||
hostPort: 32503 | ||
protocol: TCP | ||
EOF | ||
|
||
# setup cluster with kind, to safely test in a sandbox | ||
if kind get clusters | grep "kubectl-envsubst"; then | ||
kind delete clusters "kubectl-envsubst" | ||
fi | ||
kind create cluster --config=kind-config.yaml | ||
kubectl config set-context "kind-kubectl-envsubst" | ||
rm -f kind-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# setup envs | ||
export PROJECT_ROOT_NAMESPACE=kubectl-envubst-examples | ||
export PROJECT_ENV=dev | ||
export PROJECT_NAME=nginx-gateway | ||
export PROJECT_NAMESPACE="${PROJECT_ROOT_NAMESPACE}-${PROJECT_ENV}" | ||
export IMAGE_NAME=nginx | ||
export IMAGE_TAG=latest | ||
|
||
# setup namespace and context | ||
kubectl create ns "${PROJECT_NAMESPACE}" --dry-run=client -oyaml | kubectl apply -f - | ||
kubectl config set-context --current --namespace="${PROJECT_NAMESPACE}" | ||
|
||
# substitute and apply resources, according to the environment (dev, stage, prod) | ||
export ENVSUBST_ALLOWED_PREFIXES='PROJECT_,IMAGE_' | ||
kubectl envsubst apply -f "${PROJECT_ENV}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# setup envs | ||
export PROJECT_ROOT_NAMESPACE=kubectl-envubst-examples | ||
export PROJECT_ENV=stage | ||
export PROJECT_NAME=nginx-gateway | ||
export PROJECT_NAMESPACE="${PROJECT_ROOT_NAMESPACE}-${PROJECT_ENV}" | ||
export IMAGE_NAME=nginx | ||
export IMAGE_TAG=latest | ||
|
||
# setup namespace and context | ||
kubectl create ns "${PROJECT_NAMESPACE}" --dry-run=client -oyaml | kubectl apply -f - | ||
kubectl config set-context --current --namespace="${PROJECT_NAMESPACE}" | ||
|
||
# substitute and apply resources, according to the environment (dev, stage, prod) | ||
export ENVSUBST_ALLOWED_PREFIXES='PROJECT_,IMAGE_' | ||
kubectl envsubst apply -f "${PROJECT_ENV}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# setup envs | ||
export PROJECT_ROOT_NAMESPACE=kubectl-envubst-examples | ||
export PROJECT_ENV=prod | ||
export PROJECT_NAME=nginx-gateway | ||
export PROJECT_NAMESPACE="${PROJECT_ROOT_NAMESPACE}-${PROJECT_ENV}" | ||
export IMAGE_NAME=nginx | ||
export IMAGE_TAG=latest | ||
|
||
# setup namespace and context | ||
kubectl create ns "${PROJECT_NAMESPACE}" --dry-run=client -oyaml | kubectl apply -f - | ||
kubectl config set-context --current --namespace="${PROJECT_NAMESPACE}" | ||
|
||
# substitute and apply resources, according to the environment (dev, stage, prod) | ||
export ENVSUBST_ALLOWED_PREFIXES='PROJECT_,IMAGE_' | ||
kubectl envsubst apply -f "${PROJECT_ENV}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## A brief example of usage | ||
|
||
### Prerequisites: | ||
|
||
You can use a Kind cluster for testing. If you haven’t installed it yet, check out the [Kind installation guide](https://kind.sigs.k8s.io/). | ||
|
||
### Deploy: | ||
|
||
Execute scripts one by one: | ||
``` | ||
# prepare kind cluster | ||
bash 00-setup-kind.sh | ||
# deploy for each environment | ||
bash 01-deploy-dev.sh | ||
bash 02-deploy-stage.sh | ||
bash 03-deploy-prod.sh | ||
``` | ||
|
||
### Verification: | ||
|
||
Check the result: | ||
- dev: http://localhost:32501 | ||
- stage: http://localhost:32502 | ||
- prod: http://localhost:32503 | ||
|
||
_If your Kind cluster is running on a remote machine, replace ‘localhost’ with the machine’s IP address._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: nginx-index | ||
data: | ||
index.html: | | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello from ${PROJECT_ENV}</title> | ||
</head> | ||
<body> | ||
<h1>Welcome to the NGINX Test Page!</h1> | ||
<p>Current env: ${PROJECT_ENV}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: &app ${PROJECT_NAME} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: *app | ||
template: | ||
metadata: | ||
labels: | ||
app: *app | ||
spec: | ||
containers: | ||
- name: *app | ||
image: $IMAGE_NAME:$IMAGE_TAG | ||
ports: | ||
- containerPort: 80 | ||
volumeMounts: | ||
- name: nginx-html | ||
mountPath: /usr/share/nginx/html/index.html | ||
subPath: index.html | ||
resources: {} | ||
volumes: | ||
- name: nginx-html | ||
configMap: | ||
name: nginx-index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: &app ${PROJECT_NAME} | ||
labels: | ||
app: *app | ||
spec: | ||
type: NodePort | ||
ports: | ||
- port: 8080 | ||
targetPort: 80 | ||
nodePort: 32501 | ||
name: *app | ||
selector: | ||
app: *app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: nginx-index | ||
data: | ||
index.html: | | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello from ${PROJECT_ENV}</title> | ||
</head> | ||
<body> | ||
<h1>Welcome to the NGINX Test Page!</h1> | ||
<p>Current env: ${PROJECT_ENV}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: &app ${PROJECT_NAME} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: *app | ||
template: | ||
metadata: | ||
labels: | ||
app: *app | ||
spec: | ||
containers: | ||
- name: *app | ||
image: $IMAGE_NAME:$IMAGE_TAG | ||
ports: | ||
- containerPort: 80 | ||
volumeMounts: | ||
- name: nginx-html | ||
mountPath: /usr/share/nginx/html/index.html | ||
subPath: index.html | ||
resources: {} | ||
volumes: | ||
- name: nginx-html | ||
configMap: | ||
name: nginx-index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: &app ${PROJECT_NAME} | ||
labels: | ||
app: *app | ||
spec: | ||
type: NodePort | ||
ports: | ||
- port: 8080 | ||
targetPort: 80 | ||
nodePort: 32503 | ||
name: *app | ||
selector: | ||
app: *app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: nginx-index | ||
data: | ||
index.html: | | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello from ${PROJECT_ENV}</title> | ||
</head> | ||
<body> | ||
<h1>Welcome to the NGINX Test Page!</h1> | ||
<p>Current env: ${PROJECT_ENV}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: &app ${PROJECT_NAME} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: *app | ||
template: | ||
metadata: | ||
labels: | ||
app: *app | ||
spec: | ||
containers: | ||
- name: *app | ||
image: $IMAGE_NAME:$IMAGE_TAG | ||
ports: | ||
- containerPort: 80 | ||
volumeMounts: | ||
- name: nginx-html | ||
mountPath: /usr/share/nginx/html/index.html | ||
subPath: index.html | ||
resources: {} | ||
volumes: | ||
- name: nginx-html | ||
configMap: | ||
name: nginx-index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: &app ${PROJECT_NAME} | ||
labels: | ||
app: *app | ||
spec: | ||
type: NodePort | ||
ports: | ||
- port: 8080 | ||
targetPort: 80 | ||
nodePort: 32502 | ||
name: *app | ||
selector: | ||
app: *app |