From 6d1cefacfd07cb9d1d459243b50837573d1a622c Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Fri, 18 Sep 2020 08:40:02 +1000 Subject: [PATCH] deploy examples to k8s --- .../applications/playlists-api/deploy.yaml | 89 +++++++++++++++++++ .../applications/videos-api/deploy.yaml | 89 +++++++++++++++++++ .../applications/videos-web/deploy.yaml | 44 +++++++++ kubernetes/servicemesh/readme.md | 72 ++++++++++++++- 4 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 kubernetes/servicemesh/applications/playlists-api/deploy.yaml create mode 100644 kubernetes/servicemesh/applications/videos-api/deploy.yaml create mode 100644 kubernetes/servicemesh/applications/videos-web/deploy.yaml diff --git a/kubernetes/servicemesh/applications/playlists-api/deploy.yaml b/kubernetes/servicemesh/applications/playlists-api/deploy.yaml new file mode 100644 index 0000000..e886212 --- /dev/null +++ b/kubernetes/servicemesh/applications/playlists-api/deploy.yaml @@ -0,0 +1,89 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: playlists-api + labels: + app: playlists-api +spec: + selector: + matchLabels: + app: playlists-api + replicas: 1 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + template: + metadata: + labels: + app: playlists-api + spec: + containers: + - name: playlists-api + image: aimvector/service-mesh:playlists-api-1.0.0 + ports: + - containerPort: 10010 + env: + - name: "ENVIRONMENT" + value: "DEBUG" + - name: "REDIS_HOST" + value: "playlists-db" + - name: "REDIS_PORT" + value: "6379" +--- +apiVersion: v1 +kind: Service +metadata: + name: playlists-api + labels: + app: playlists-api +spec: + type: ClusterIP + selector: + app: playlists-api + ports: + - protocol: TCP + name: http + port: 80 + targetPort: 10010 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: playlists-db + labels: + app: playlists-db +spec: + selector: + matchLabels: + app: playlists-db + replicas: 1 + template: + metadata: + labels: + app: playlists-db + spec: + containers: + - name: playlists-api + image: redis:6.0-alpine + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: playlists-db + labels: + app: playlists-db +spec: + type: ClusterIP + selector: + app: playlists-db + ports: + - protocol: TCP + name: http + port: 6379 + targetPort: 6379 + + diff --git a/kubernetes/servicemesh/applications/videos-api/deploy.yaml b/kubernetes/servicemesh/applications/videos-api/deploy.yaml new file mode 100644 index 0000000..35d26fe --- /dev/null +++ b/kubernetes/servicemesh/applications/videos-api/deploy.yaml @@ -0,0 +1,89 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: videos-api + labels: + app: videos-api +spec: + selector: + matchLabels: + app: videos-api + replicas: 1 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + template: + metadata: + labels: + app: videos-api + spec: + containers: + - name: videos-api + image: aimvector/service-mesh:videos-api-1.0.0 + ports: + - containerPort: 10010 + env: + - name: "ENVIRONMENT" + value: "DEBUG" + - name: "REDIS_HOST" + value: "videos-db" + - name: "REDIS_PORT" + value: "6379" +--- +apiVersion: v1 +kind: Service +metadata: + name: videos-api + labels: + app: videos-api +spec: + type: ClusterIP + selector: + app: videos-api + ports: + - protocol: TCP + name: http + port: 10010 + targetPort: 10010 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: videos-db + labels: + app: videos-db +spec: + selector: + matchLabels: + app: videos-db + replicas: 1 + template: + metadata: + labels: + app: videos-db + spec: + containers: + - name: videos-db + image: redis:6.0-alpine + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: videos-db + labels: + app: videos-db +spec: + type: ClusterIP + selector: + app: videos-db + ports: + - protocol: TCP + name: http + port: 6379 + targetPort: 6379 + + diff --git a/kubernetes/servicemesh/applications/videos-web/deploy.yaml b/kubernetes/servicemesh/applications/videos-web/deploy.yaml new file mode 100644 index 0000000..74e041f --- /dev/null +++ b/kubernetes/servicemesh/applications/videos-web/deploy.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: videos-web + labels: + app: videos-web +spec: + selector: + matchLabels: + app: videos-web + replicas: 1 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + template: + metadata: + labels: + app: videos-web + spec: + containers: + - name: videos-web + image: aimvector/service-mesh:videos-web-1.0.0 + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: videos-web + labels: + app: videos-web +spec: + type: ClusterIP + selector: + app: videos-web + ports: + - protocol: TCP + name: http + port: 80 + targetPort: 80 + + diff --git a/kubernetes/servicemesh/readme.md b/kubernetes/servicemesh/readme.md index 71f7833..2384be7 100644 --- a/kubernetes/servicemesh/readme.md +++ b/kubernetes/servicemesh/readme.md @@ -111,9 +111,11 @@ This is intentional to demonstrate a busy network. +------------+ +-----------+ ``` +
-## Run the apps - +## Run the apps: Docker +
+
There is a `docker-compose.yaml` in this directory.
Change your terminal to this folder and run: @@ -124,4 +126,68 @@ docker-compose up ``` -You can access the app on `http://localhost` \ No newline at end of file +You can access the app on `http://localhost` + +
+ +## Run the apps: Kubernetes +
+
+ +Create a cluster with [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) + +``` +kind create cluster --name servicemesh --image kindest/node:v1.18.4 +``` +
+ +### Deploy videos-web + +
+
+ +``` +cd ./kubernetes/servicemesh/ + +kubectl apply -f applications/videos-web/deploy.yaml +kubectl port-forward svc/videos-web 80:80 + +``` + +You should see blank page at `http://localhost/`
+It's blank because it needs the `playlists-api` to get data + +
+ +### Deploy playlists-api and database + +
+
+ +``` +cd ./kubernetes/servicemesh/ + +kubectl apply -f applications/playlists-api/deploy.yaml +kubectl port-forward svc/playlists-api 81:80 + +``` + +You should see empty playlists page at `http://localhost/`
+Playlists are empty because it needs the `videos-api` to get video data
+ +
+ +### Deploy videos-api and database + +
+
+ +``` +cd ./kubernetes/servicemesh/ + +kubectl apply -f applications/videos-api/deploy.yaml + +``` + +Refresh page at `http://localhost/`
+You should now see the complete architecture in the browser
\ No newline at end of file