Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Sep 1, 2020
0 parents commit 56bca25
Show file tree
Hide file tree
Showing 48 changed files with 684 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Fleet Examples

This repository contains examples of how to use Fleet using different approaches.

| Example | Description |
|-------------|-------------|
| [simple](simple/) | The minimally viable repo to deploy raw Kubernetes resources |
| [manifest](manifest/) | A full example of using raw Kubernetes YAML and customizing it per target cluster |
| [helm](helm/) | A full example of using Helm and customizing it per target cluster |
| [kustomize](kustomize/) | A full example of using Kustomize and customizing it per target cluster |
11 changes: 11 additions & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Helm Example

This example will deploy the [Kubernetes sample guestbook](https://github.com/kubernetes/examples/tree/master/guestbook/) application as
packaged as a Helm chart.
The app will be deployed into the `fleet-helm-example` namespace.

The application will be customized as follows per environment:

* Dev clusters: Only the redis leader is deployed and not the followers.
* Test clusters: Scale the front deployment to 3
* Prod clusters: Scale the front deployment to 3 and set the service type to LoadBalancer
5 changes: 5 additions & 0 deletions helm/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: guestbook
description: Sample application
version: 0.0.0
appVersion: 0.0.0
25 changes: 25 additions & 0 deletions helm/chart/templates/frontend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
selector:
matchLabels:
app: guestbook
tier: frontend
replicas: {{ .Values.replicas }}
template:
metadata:
labels:
app: guestbook
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google-samples/gb-frontend:v4
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 80
14 changes: 14 additions & 0 deletions helm/chart/templates/frontend-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
type: "{{ .Values.serviceType }}"
ports:
- port: 80
selector:
app: guestbook
tier: frontend
27 changes: 27 additions & 0 deletions helm/chart/templates/redis-master-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-master
spec:
selector:
matchLabels:
app: redis
role: master
tier: backend
replicas: 1
template:
metadata:
labels:
app: redis
role: master
tier: backend
spec:
containers:
- name: master
image: redis
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
16 changes: 16 additions & 0 deletions helm/chart/templates/redis-master-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
app: redis
role: master
tier: backend
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
role: master
tier: backend
29 changes: 29 additions & 0 deletions helm/chart/templates/redis-slave-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{ if .Values.replication }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-slave
spec:
selector:
matchLabels:
app: redis
role: slave
tier: backend
replicas: 2
template:
metadata:
labels:
app: redis
role: slave
tier: backend
spec:
containers:
- name: slave
image: gcr.io/google_samples/gb-redisslave:v1
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
{{ end }}
19 changes: 19 additions & 0 deletions helm/chart/templates/redis-slave-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: redis-slave
labels:
app: redis
role: slave
tier: backend
spec:
ports:
- port: 6379
selector:
app: redis
{{ if .Values.replication }}
role: slave
{{ else }}
role: master
{{ end }}
tier: backend
3 changes: 3 additions & 0 deletions helm/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
replication: true
replicas: 1
serviceType: NodePort
23 changes: 23 additions & 0 deletions helm/fleet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace: fleet-helm-example
targets:
- name: dev
values:
replication: false
clusterSelector:
matchLabels:
env: dev

- name: test
values:
replicas: 3
clusterSelector:
matchLabels:
env: test

- name: prod
values:
serviceType: LoadBalancer
replicas: 3
clusterSelector:
matchLabels:
env: prod
10 changes: 10 additions & 0 deletions kustomize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Helm Example

This example will deploy the [Kubernetes sample guestbook](https://github.com/kubernetes/examples/tree/master/guestbook/) application
using kustomize. The app will be deployed into the `fleet-kustomize-example` namespace.

The application will be customized as follows per environment:

* Dev clusters: Only the redis leader is deployed and not the followers.
* Test clusters: Scale the front deployment to 3
* Prod clusters: Scale the front deployment to 3 and set the service type to LoadBalancer
22 changes: 22 additions & 0 deletions kustomize/fleet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace: fleet-kustomize-example
targets:
- name: dev
clusterSelector:
matchLabels:
env: dev
# NOTE: This directory is always relative to ./kustomize
kustomizeDir: overlays/dev

- name: test
clusterSelector:
matchLabels:
env: test
# NOTE: This directory is always relative to ./kustomize
kustomizeDir: overlays/test

- name: prod
clusterSelector:
matchLabels:
env: prod
# NOTE: This directory is always relative to ./kustomize
kustomizeDir: overlays/prod
25 changes: 25 additions & 0 deletions kustomize/kustomize/base/frontend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
selector:
matchLabels:
app: guestbook
tier: frontend
replicas: 1
template:
metadata:
labels:
app: guestbook
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google-samples/gb-frontend:v4
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 80
14 changes: 14 additions & 0 deletions kustomize/kustomize/base/frontend-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
type: NodePort
ports:
- port: 80
selector:
app: guestbook
tier: frontend
7 changes: 7 additions & 0 deletions kustomize/kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resources:
- frontend-deployment.yaml
- frontend-service.yaml
- redis-master-deployment.yaml
- redis-master-service.yaml
- redis-slave-deployment.yaml
- redis-slave-service.yaml
27 changes: 27 additions & 0 deletions kustomize/kustomize/base/redis-master-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-master
spec:
selector:
matchLabels:
app: redis
role: master
tier: backend
replicas: 1
template:
metadata:
labels:
app: redis
role: master
tier: backend
spec:
containers:
- name: master
image: redis
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
16 changes: 16 additions & 0 deletions kustomize/kustomize/base/redis-master-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
app: redis
role: master
tier: backend
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
role: master
tier: backend
27 changes: 27 additions & 0 deletions kustomize/kustomize/base/redis-slave-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-slave
spec:
selector:
matchLabels:
app: redis
role: slave
tier: backend
replicas: 2
template:
metadata:
labels:
app: redis
role: slave
tier: backend
spec:
containers:
- name: slave
image: gcr.io/google_samples/gb-redisslave:v1
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
15 changes: 15 additions & 0 deletions kustomize/kustomize/base/redis-slave-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: redis-slave
labels:
app: redis
role: slave
tier: backend
spec:
ports:
- port: 6379
selector:
app: redis
role: slave
tier: backend
2 changes: 2 additions & 0 deletions kustomize/kustomize/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- overlays/dev
5 changes: 5 additions & 0 deletions kustomize/kustomize/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resources:
- ../../base
patches:
- redis-slave-deployment.yaml
- redis-slave-service.yaml
6 changes: 6 additions & 0 deletions kustomize/kustomize/overlays/dev/redis-slave-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: redis-slave
spec:
replicas: 0
7 changes: 7 additions & 0 deletions kustomize/kustomize/overlays/dev/redis-slave-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Service
apiVersion: v1
metadata:
name: redis-slave
spec:
selector:
role: master
6 changes: 6 additions & 0 deletions kustomize/kustomize/overlays/prod/frontend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 3
Loading

0 comments on commit 56bca25

Please # to comment.