Add Kubernetes TypeScript Sock Shop example
ADD
kubernetes-ts-sock-shop/Pulumi.yaml
+name: sock-shop
+runtime: nodejs
+description: The standard Weaveworks Sock Shop demo based on https://github.com/microservices-demo/microservices-demo
+

ADD
kubernetes-ts-sock-shop/README.md
+# Kubernetes Guestbook
+
+A version of the standard [Sock Shop microservices reference app](https://github.com/microservices-demo/microservices-demo) app using
+Pulumi and `@pulumi/kubernetes`.
+
+## Running the App
+
+Follow the steps in [Pulumi Installation and Setup](https://docs.pulumi.com/install/) and [Configuring Pulumi
+Kubernetes](https://docs.pulumi.com/reference/kubernetes.html#configuration) to get setup with Pulumi and Kubernetes.
+
+Install dependencies:
+
+```sh
+npm install
+```
+
+Create a new stack:
+
+```sh
+$ pulumi stack init
+Enter a stack name: testing
+```
+
+Preview the deployment of the application:
+
+```sh
+$ pulumi preview
+Previewing update of stack 'testing'
+Previewing changes:
+
+ Type Name Plan Info
+ + pulumi:pulumi:Stack sock-shop-testing create
+ + kubernetes:core:Service carts-db create
+ + kubernetes:core:Service carts create
+ + kubernetes:core:Service catalog-db create
+ + kubernetes:core:Service catalog create
+ + kubernetes:core:Service orders-db create
+ + kubernetes:core:Service orders create
+ + kubernetes:core:Service payment create
+ + kubernetes:core:Service rabbitmq create
+ + kubernetes:core:Service shipping create
+ + kubernetes:core:Service user-db create
+ + kubernetes:core:Service user create
+ + kubernetes:core:Service front-end create
+ + kubernetes:core:Service queue-master create
+ + kubernetes:apps:Deployment queue-master create
+ + kubernetes:apps:Deployment catalog-db create
+ + kubernetes:apps:Deployment catalog create
+ + kubernetes:apps:Deployment payment create
+ + kubernetes:apps:Deployment rabbitmq create
+ + kubernetes:apps:Deployment front-end create
+ + kubernetes:apps:Deployment carts-db create
+ + kubernetes:apps:Deployment orders-db create
+ + kubernetes:apps:Deployment user-db create
+ + kubernetes:apps:Deployment user create
+ + kubernetes:apps:Deployment carts create
+ + kubernetes:apps:Deployment orders create
+ + kubernetes:apps:Deployment shipping create
+
+info: 27 changes previewed:
+ + 27 resources to create
+```
+
+Perform the deployment:
+
+```sh
+$ pulumi update
+Updating stack 'testing'
+Performing changes:
+
+ Type Name Status Info
+ + kubernetes:core:Service carts-db created
+ + kubernetes:core:Service carts created
+ + kubernetes:core:Service catalog-db created
+ + kubernetes:core:Service catalog created
+ + kubernetes:core:Service orders-db created
+ + kubernetes:core:Service orders created
+ + kubernetes:core:Service payment created
+ + kubernetes:core:Service rabbitmq created
+ + kubernetes:core:Service shipping created
+ + kubernetes:core:Service user-db created
+ + kubernetes:core:Service user created
+ + kubernetes:core:Service front-end created
+ + kubernetes:core:Service queue-master created
+ + kubernetes:apps:Deployment queue-master created
+ + kubernetes:apps:Deployment catalog-db created
+ + kubernetes:apps:Deployment catalog created
+ + kubernetes:apps:Deployment payment created
+ + kubernetes:apps:Deployment rabbitmq created
+ + kubernetes:apps:Deployment front-end created
+ + kubernetes:apps:Deployment carts-db created
+ + kubernetes:apps:Deployment orders-db created
+ + kubernetes:apps:Deployment user-db created
+ + kubernetes:apps:Deployment user created
+ + kubernetes:apps:Deployment carts created
+ + kubernetes:apps:Deployment orders created
+ + kubernetes:apps:Deployment shipping created
+
+info: 27 changes performed:
+ + 27 resources created
+Update duration: 3m2.127835854s
+
+Permalink: https://pulumi.com/examples/testing/updates/1
+```
+
+The application is now deployed. Use `kubectl` to see the deployed services.
+
+```sh
+$ k get services -n sock-shop
+NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
+carts 10.47.242.164 <none> 80/TCP 4m
+carts-db 10.47.245.60 <none> 27017/TCP 4m
+catalogue 10.47.255.170 <none> 80/TCP 4m
+catalogue-db 10.47.252.96 <none> 3306/TCP 4m
+front-end 10.47.247.63 <nodes> 80:30001/TCP 4m
+orders 10.47.255.197 <none> 80/TCP 4m
+orders-db 10.47.242.209 <none> 27017/TCP 4m
+payment 10.47.254.192 <none> 80/TCP 4m
+queue-master 10.47.251.206 <none> 80/TCP 4m
+rabbitmq 10.47.254.26 <none> 5672/TCP 4m
+shipping 10.47.247.218 <none> 80/TCP 4m
+user-db 10.47.242.91 <none> 27017/TCP 4m
+user 10.47.242.91 <none> 27017/TCP 4m
+```

ADD
kubernetes-ts-sock-shop/index.ts
+// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
+
+import * as pulumi from "@pulumi/pulumi";
+import * as k8s from "@pulumi/kubernetes";
+
+// --------------------------------------------------------------------------
+// Carts microservice.
+// --------------------------------------------------------------------------
+
+const cartsDb = new k8s.apps.v1beta1.Deployment(
+ "carts-db",
+ {
+ "metadata": {
+ "name": "carts-db",
+ "labels": {
+ "name": "carts-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "carts-db"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "carts-db",
+ "image": "mongo",
+ "ports": [
+ {
+ "name": "mongo",
+ "containerPort": 27017
+ }
+ ],
+ "securityContext": {
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "CHOWN",
+ "SETGID",
+ "SETUID"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ },
+ "volumeMounts": [
+ {
+ "mountPath": "/tmp",
+ "name": "tmp-volume"
+ }
+ ]
+ }
+ ],
+ "volumes": [
+ {
+ "name": "tmp-volume",
+ "emptyDir": {
+ "medium": "Memory"
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const cartsDbService = new k8s.core.v1.Service(
+ "carts-db",
+ {
+ "metadata": {
+ "name": "carts-db",
+ "labels": {
+ "name": "carts-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 27017,
+ "targetPort": 27017
+ }
+ ],
+ "selector": {
+ "name": "carts-db"
+ }
+ }
+ });
+
+const carts = new k8s.apps.v1beta1.Deployment(
+ "carts",
+ {
+ "metadata": {
+ "name": "carts",
+ "labels": {
+ "name": "carts"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "carts"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "carts",
+ "image": "weaveworksdemos/carts:0.4.8",
+ "ports": [
+ {
+ "containerPort": 80
+ }
+ ],
+ "env": [
+ {
+ "name": "ZIPKIN",
+ "value": "zipkin.jaeger.svc.cluster.local"
+ },
+ {
+ "name": "JAVA_OPTS",
+ "value": "-Xms64m -Xmx128m -XX:PermSize=32m -XX:MaxPermSize=64m -XX:+UseG1GC -Djava.security.egd=file:/dev/urandom"
+ }
+ ],
+ "securityContext": {
+ "runAsNonRoot": true,
+ "runAsUser": 10001,
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "NET_BIND_SERVICE"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ },
+ "volumeMounts": [
+ {
+ "mountPath": "/tmp",
+ "name": "tmp-volume"
+ }
+ ]
+ }
+ ],
+ "volumes": [
+ {
+ "name": "tmp-volume",
+ "emptyDir": {
+ "medium": "Memory"
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const cartsService = new k8s.core.v1.Service(
+ "carts",
+ {
+ "metadata": {
+ "name": "carts",
+ "labels": {
+ "name": "carts"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 80
+ }
+ ],
+ "selector": {
+ "name": "carts"
+ }
+ }
+ });
+
+// --------------------------------------------------------------------------
+// Catalog microservice.
+// --------------------------------------------------------------------------
+
+const catalogDb = new k8s.apps.v1beta1.Deployment(
+ "catalog-db",
+ {
+ "metadata": {
+ "name": "catalogue-db",
+ "labels": {
+ "name": "catalogue-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "catalogue-db"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "catalogue-db",
+ "image": "weaveworksdemos/catalogue-db:0.3.0",
+ "env": [
+ {
+ "name": "MYSQL_ROOT_PASSWORD",
+ "value": "fake_password"
+ },
+ {
+ "name": "MYSQL_DATABASE",
+ "value": "socksdb"
+ }
+ ],
+ "ports": [
+ {
+ "name": "mysql",
+ "containerPort": 3306
+ }
+ ]
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const catalogDbService = new k8s.core.v1.Service(
+ "catalog-db",
+ {
+ "metadata": {
+ "name": "catalogue-db",
+ "labels": {
+ "name": "catalogue-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 3306,
+ "targetPort": 3306
+ }
+ ],
+ "selector": {
+ "name": "catalogue-db"
+ }
+ }
+ });
+
+const catalog = new k8s.apps.v1beta1.Deployment(
+ "catalog",
+ {
+ "metadata": {
+ "name": "catalogue",
+ "labels": {
+ "name": "catalogue"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "catalogue"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "catalogue",
+ "image": "weaveworksdemos/catalogue:0.3.5",
+ "ports": [
+ {
+ "containerPort": 80
+ }
+ ],
+ "securityContext": {
+ "runAsNonRoot": true,
+ "runAsUser": 10001,
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "NET_BIND_SERVICE"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const catalogService = new k8s.core.v1.Service(
+ "catalog",
+ {
+ "metadata": {
+ "name": "catalogue",
+ "labels": {
+ "name": "catalogue"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 80
+ }
+ ],
+ "selector": {
+ "name": "catalogue"
+ }
+ }
+ });
+
+// --------------------------------------------------------------------------
+// Frontend microservice.
+// --------------------------------------------------------------------------
+
+const frontend = new k8s.apps.v1beta1.Deployment(
+ "front-end",
+ {
+ "metadata": {
+ "name": "front-end",
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "front-end"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "front-end",
+ "image": "weaveworksdemos/front-end:0.3.12",
+ "resources": {
+ "requests": {
+ "cpu": "100m",
+ "memory": "100Mi"
+ }
+ },
+ "ports": [
+ {
+ "containerPort": 8079
+ }
+ ],
+ "securityContext": {
+ "runAsNonRoot": true,
+ "runAsUser": 10001,
+ "capabilities": {
+ "drop": [
+ "all"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const frontendService = new k8s.core.v1.Service(
+ "front-end",
+ {
+ "metadata": {
+ "name": "front-end",
+ "labels": {
+ "name": "front-end"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "type": "NodePort",
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 8079,
+ "nodePort": 30001
+ }
+ ],
+ "selector": {
+ "name": "front-end"
+ }
+ }
+ });
+
+// --------------------------------------------------------------------------
+// Orders microservice.
+// --------------------------------------------------------------------------
+
+const ordersDb = new k8s.apps.v1beta1.Deployment(
+ "orders-db",
+ {
+ "metadata": {
+ "name": "orders-db",
+ "labels": {
+ "name": "orders-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "orders-db"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "orders-db",
+ "image": "mongo",
+ "ports": [
+ {
+ "name": "mongo",
+ "containerPort": 27017
+ }
+ ],
+ "securityContext": {
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "CHOWN",
+ "SETGID",
+ "SETUID"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ },
+ "volumeMounts": [
+ {
+ "mountPath": "/tmp",
+ "name": "tmp-volume"
+ }
+ ]
+ }
+ ],
+ "volumes": [
+ {
+ "name": "tmp-volume",
+ "emptyDir": {
+ "medium": "Memory"
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const ordersDbService = new k8s.core.v1.Service(
+ "orders-db",
+ {
+ "metadata": {
+ "name": "orders-db",
+ "labels": {
+ "name": "orders-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 27017,
+ "targetPort": 27017
+ }
+ ],
+ "selector": {
+ "name": "orders-db"
+ }
+ }
+ });
+
+const orders = new k8s.apps.v1beta1.Deployment(
+ "orders",
+ {
+ "metadata": {
+ "name": "orders",
+ "labels": {
+ "name": "orders"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "orders"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "orders",
+ "image": "weaveworksdemos/orders:0.4.7",
+ "env": [
+ {
+ "name": "ZIPKIN",
+ "value": "zipkin.jaeger.svc.cluster.local"
+ },
+ {
+ "name": "JAVA_OPTS",
+ "value": "-Xms64m -Xmx128m -XX:PermSize=32m -XX:MaxPermSize=64m -XX:+UseG1GC -Djava.security.egd=file:/dev/urandom"
+ }
+ ],
+ "ports": [
+ {
+ "containerPort": 80
+ }
+ ],
+ "securityContext": {
+ "runAsNonRoot": true,
+ "runAsUser": 10001,
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "NET_BIND_SERVICE"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ },
+ "volumeMounts": [
+ {
+ "mountPath": "/tmp",
+ "name": "tmp-volume"
+ }
+ ]
+ }
+ ],
+ "volumes": [
+ {
+ "name": "tmp-volume",
+ "emptyDir": {
+ "medium": "Memory"
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const ordersService = new k8s.core.v1.Service(
+ "orders",
+ {
+ "metadata": {
+ "name": "orders",
+ "labels": {
+ "name": "orders"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 80
+ }
+ ],
+ "selector": {
+ "name": "orders"
+ }
+ }
+ });
+
+// --------------------------------------------------------------------------
+// Payment microservice.
+// --------------------------------------------------------------------------
+
+const payment = new k8s.apps.v1beta1.Deployment(
+ "payment",
+ {
+ "metadata": {
+ "name": "payment",
+ "labels": {
+ "name": "payment"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "payment"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "payment",
+ "image": "weaveworksdemos/payment:0.4.3",
+ "ports": [
+ {
+ "containerPort": 80
+ }
+ ],
+ "securityContext": {
+ "runAsNonRoot": true,
+ "runAsUser": 10001,
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "NET_BIND_SERVICE"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const paymentService = new k8s.core.v1.Service(
+ "payment",
+ {
+ "metadata": {
+ "name": "payment",
+ "labels": {
+ "name": "payment"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 80
+ }
+ ],
+ "selector": {
+ "name": "payment"
+ }
+ }
+ });
+
+// --------------------------------------------------------------------------
+// Queue microservice.
+// --------------------------------------------------------------------------
+
+const queueMaster = new k8s.apps.v1beta1.Deployment(
+ "queue-master",
+ {
+ "metadata": {
+ "name": "queue-master",
+ "labels": {
+ "name": "queue-master"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "queue-master"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "queue-master",
+ "image": "weaveworksdemos/queue-master:0.3.1",
+ "ports": [
+ {
+ "containerPort": 80
+ }
+ ]
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const queueMasterService = new k8s.core.v1.Service(
+ "queue-master",
+ {
+ "metadata": {
+ "name": "queue-master",
+ "labels": {
+ "name": "queue-master"
+ },
+ "annotations": {
+ "prometheus.io/path": "/prometheus"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 80
+ }
+ ],
+ "selector": {
+ "name": "queue-master"
+ }
+ }
+ });
+
+const rabbitmq = new k8s.apps.v1beta1.Deployment(
+ "rabbitmq",
+ {
+ "metadata": {
+ "name": "rabbitmq",
+ "labels": {
+ "name": "rabbitmq"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "rabbitmq"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "rabbitmq",
+ "image": "rabbitmq:3.6.8",
+ "ports": [
+ {
+ "containerPort": 5672
+ }
+ ],
+ "securityContext": {
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "CHOWN",
+ "SETGID",
+ "SETUID",
+ "DAC_OVERRIDE"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const rabbitmqService = new k8s.core.v1.Service(
+ "rabbitmq",
+ {
+ "metadata": {
+ "name": "rabbitmq",
+ "labels": {
+ "name": "rabbitmq"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 5672,
+ "targetPort": 5672
+ }
+ ],
+ "selector": {
+ "name": "rabbitmq"
+ }
+ }
+ });
+
+// --------------------------------------------------------------------------
+// Shipping microservice.
+// --------------------------------------------------------------------------
+
+const shipping = new k8s.apps.v1beta1.Deployment(
+ "shipping",
+ {
+ "metadata": {
+ "name": "shipping",
+ "labels": {
+ "name": "shipping"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "shipping"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "shipping",
+ "image": "weaveworksdemos/shipping:0.4.8",
+ "env": [
+ {
+ "name": "ZIPKIN",
+ "value": "zipkin.jaeger.svc.cluster.local"
+ },
+ {
+ "name": "JAVA_OPTS",
+ "value": "-Xms64m -Xmx128m -XX:PermSize=32m -XX:MaxPermSize=64m -XX:+UseG1GC -Djava.security.egd=file:/dev/urandom"
+ }
+ ],
+ "ports": [
+ {
+ "containerPort": 80
+ }
+ ],
+ "securityContext": {
+ "runAsNonRoot": true,
+ "runAsUser": 10001,
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "NET_BIND_SERVICE"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ },
+ "volumeMounts": [
+ {
+ "mountPath": "/tmp",
+ "name": "tmp-volume"
+ }
+ ]
+ }
+ ],
+ "volumes": [
+ {
+ "name": "tmp-volume",
+ "emptyDir": {
+ "medium": "Memory"
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const shippingService = new k8s.core.v1.Service(
+ "shipping",
+ {
+ "metadata": {
+ "name": "shipping",
+ "labels": {
+ "name": "shipping"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 80
+ }
+ ],
+ "selector": {
+ "name": "shipping"
+ }
+ }
+ });
+
+// --------------------------------------------------------------------------
+// User microservice.
+// --------------------------------------------------------------------------
+
+const userDb = new k8s.apps.v1beta1.Deployment(
+ "user-db",
+ {
+ "metadata": {
+ "name": "user-db",
+ "labels": {
+ "name": "user-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "user-db"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "user-db",
+ "image": "weaveworksdemos/user-db:0.4.0",
+ "ports": [
+ {
+ "name": "mongo",
+ "containerPort": 27017
+ }
+ ],
+ "securityContext": {
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "CHOWN",
+ "SETGID",
+ "SETUID"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ },
+ "volumeMounts": [
+ {
+ "mountPath": "/tmp",
+ "name": "tmp-volume"
+ }
+ ]
+ }
+ ],
+ "volumes": [
+ {
+ "name": "tmp-volume",
+ "emptyDir": {
+ "medium": "Memory"
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const userDbService = new k8s.core.v1.Service(
+ "user-db",
+ {
+ "metadata": {
+ "name": "user-db",
+ "labels": {
+ "name": "user-db"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 27017,
+ "targetPort": 27017
+ }
+ ],
+ "selector": {
+ "name": "user-db"
+ }
+ }
+ });
+
+const user = new k8s.apps.v1beta1.Deployment(
+ "user",
+ {
+ "metadata": {
+ "name": "user",
+ "labels": {
+ "name": "user"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "replicas": 1,
+ "template": {
+ "metadata": {
+ "labels": {
+ "name": "user"
+ }
+ },
+ "spec": {
+ "containers": [
+ {
+ "name": "user",
+ "image": "weaveworksdemos/user:0.4.7",
+ "ports": [
+ {
+ "containerPort": 80
+ }
+ ],
+ "env": [
+ {
+ "name": "MONGO_HOST",
+ "value": "user-db:27017"
+ }
+ ],
+ "securityContext": {
+ "runAsNonRoot": true,
+ "runAsUser": 10001,
+ "capabilities": {
+ "drop": [
+ "all"
+ ],
+ "add": [
+ "NET_BIND_SERVICE"
+ ]
+ },
+ "readOnlyRootFilesystem": true
+ }
+ }
+ ],
+ "nodeSelector": {
+ "beta.kubernetes.io/os": "linux"
+ }
+ }
+ }
+ }
+ });
+
+const userService = new k8s.core.v1.Service(
+ "user",
+ {
+ "metadata": {
+ "name": "user",
+ "labels": {
+ "name": "user"
+ },
+ "namespace": "sock-shop"
+ },
+ "spec": {
+ "ports": [
+ {
+ "port": 80,
+ "targetPort": 80
+ }
+ ],
+ "selector": {
+ "name": "user"
+ }
+ }
+ });

ADD
kubernetes-ts-sock-shop/package.json
+{
+ "name": "sock-shop",
+ "version": "0.1.0",
+ "main": "bin/index.js",
+ "typings": "bin/index.d.ts",
+ "scripts": {
+ "build": "tsc"
+ },
+ "devDependencies": {
+ "@types/node": "^9.3.0",
+ "typescript": "^2.5.3"
+ },
+ "dependencies": {
+ "@pulumi/kubernetes": "^0.13",
+ "@pulumi/pulumi": "^0.12"
+ },
+ "license": "MIT"
+}

ADD
kubernetes-ts-sock-shop/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es6",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "declaration": true,
+ "sourceMap": true,
+ "stripInternal": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true,
+ "strictNullChecks": true
+ },
+ "files": [
+ "index.ts"
+ ]
+}

Add Kubernetes TypeScript Sock Shop example