From 18393c9a6aadd02af2165c6d5f056dfd573aea01 Mon Sep 17 00:00:00 2001 From: Eduard Tomas Date: Fri, 16 Jun 2017 17:40:27 +0200 Subject: [PATCH] Config files for k8s deployment of all services updated --- docker-compose.yml | 2 +- global.json | 5 ++ k8s/deploy.ps1 | 43 ++++++++++- k8s/deployments.yaml | 164 +++++++++++++++++++++++++++++++++++++++--- k8s/eShopOnAzure.json | 28 ++++++++ k8s/local.json | 27 +++++++ k8s/nginx.conf | 18 +++++ k8s/services.yaml | 44 +++++++++++- 8 files changed, 319 insertions(+), 12 deletions(-) create mode 100644 global.json create mode 100644 k8s/eShopOnAzure.json create mode 100644 k8s/local.json diff --git a/docker-compose.yml b/docker-compose.yml index 334e11537..4b9a52cdb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -108,7 +108,7 @@ services: - rabbitmq locations.api: - image: locations.api + image: eshop/locations.api build: context: ./src/Services/Location/Locations.API dockerfile: Dockerfile diff --git a/global.json b/global.json new file mode 100644 index 000000000..38fed7db6 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version":"1.0.4" + } +} \ No newline at end of file diff --git a/k8s/deploy.ps1 b/k8s/deploy.ps1 index 9930474ba..19cf7e73d 100644 --- a/k8s/deploy.ps1 +++ b/k8s/deploy.ps1 @@ -5,9 +5,12 @@ Param( [parameter(Mandatory=$false)][bool]$deployCI, [parameter(Mandatory=$false)][bool]$useDockerHub, [parameter(Mandatory=$false)][string]$execPath, - [parameter(Mandatory=$false)][string]$kubeconfigPath + [parameter(Mandatory=$false)][string]$kubeconfigPath, + [parameter(Mandatory=$true)][string]$configFile ) +$debugMode = $PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent + function ExecKube($cmd) { if($deployCI) { $kubeconfig = $kubeconfigPath + 'config'; @@ -20,6 +23,19 @@ function ExecKube($cmd) { } } + +$config = Get-Content -Raw -Path $configFile | ConvertFrom-Json + +if ($debugMode) { +Write-Host "Using following JSON config: " +$json = ConvertTo-Json $config -Depth 5 +Write-Host $json +Write-Host "Press a key " +[System.Console]::Read() +} + + + # Not used when deploying through CI VSTS if(-not $deployCI) { $requiredCommands = ("docker", "docker-compose", "kubectl") @@ -54,11 +70,13 @@ ExecKube -cmd 'delete deployments --all' ExecKube -cmd 'delete services --all' ExecKube -cmd 'delete configmap config-files' ExecKube -cmd 'delete configmap urls' +ExecKube -cmd 'delete configmap externalcfg' # start sql, rabbitmq, frontend deploymentsExecKube -cmd 'delete configmap config-files' ExecKube -cmd 'create configmap config-files --from-file=nginx-conf=nginx.conf' ExecKube -cmd 'label configmap config-files app=eshop' -ExecKube -cmd 'create -f sql-data.yaml -f basket-data.yaml -f keystore-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml' +# ExecKube -cmd 'create -f sql-data.yaml -f basket-data.yaml -f keystore-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml' +ExecKube -cmd 'create -f services.yaml -f frontend.yaml' # building and publishing docker images not necessary when deploying through CI VSTS if(-not $deployCI) { @@ -109,6 +127,27 @@ ExecKube -cmd 'create configmap urls ` ExecKube -cmd 'label configmap urls app=eshop' +Write-Host "Applying external configuration from json" -ForegroundColor Yellow + +ExecKube -cmd 'create configmap externalcfg ` + --from-literal=CatalogSqlDb=$($config.sql.catalog) ` + --from-literal=IdentitySqlDb=$($config.sql.identity) ` + --from-literal=OrderingSqlDb=$($config.sql.ordering) ` + --from-literal=MarketingSqlDb=$($config.sql.marketing) ` + --from-literal=LocationsNoSqlDb=$($config.nosql.locations.constr) ` + --from-literal=LocationsNoSqlDbName=$($config.nosql.locations.db) ` + --from-literal=MarketingsNoSqlDb=$($config.nosql.marketing.constr) ` + --from-literal=MarketingNoSqlDbName=$($config.nosql.marketing.db) ` + --from-literal=BasketRedisConStr=$($config.redis.basket) ` + --from-literal=LocationsBus=$($config.servicebus.locations) ` + --from-literal=MarketingBus=$($config.servicebus.marketing) ` + --from-literal=BasketBus=$($config.servicebus.basket) ` + --from-literal=OrderingBus=$($config.servicebus.ordering) ` + --from-literal=PaymentBus=$($config.servicebus.payment) ' + +ExecKube -cmd 'label configmap externalcfg app=eshop' + + Write-Host "Creating deployments..." -ForegroundColor Yellow ExecKube -cmd 'create -f deployments.yaml' diff --git a/k8s/deployments.yaml b/k8s/deployments.yaml index 62352e2ef..0d2f4db08 100644 --- a/k8s/deployments.yaml +++ b/k8s/deployments.yaml @@ -18,9 +18,17 @@ spec: - name: ASPNETCORE_URLS value: http://0.0.0.0:80/basket-api - name: ConnectionString - value: basket-data + valueFrom: + configMapKeyRef: + name: externalcfg + key: BasketRedisConStr - name: EventBusConnection - value: rabbitmq + valueFrom: + configMapKeyRef: + name: externalcfg + key: BasketBus + - name: AzureServiceBusEnabled + value: "true" - name: IdentityUrl valueFrom: configMapKeyRef: @@ -51,9 +59,10 @@ spec: - name: ASPNETCORE_URLS value: http://0.0.0.0:80/catalog-api - name: ConnectionString - value: "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word" - - name: EventBusConnection - value: rabbitmq + valueFrom: + configMapKeyRef: + name: externalcfg + key: CatalogSqlDb - name: ExternalCatalogBaseUrl valueFrom: configMapKeyRef: @@ -84,7 +93,10 @@ spec: - name: ASPNETCORE_URLS value: http://0.0.0.0:80/identity - name: ConnectionStrings__DefaultConnection - value: "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word" + valueFrom: + configMapKeyRef: + name: externalcfg + key: IdentitySqlDb - name: DPConnectionString value: keystore-data - name: IsClusterEnv @@ -124,9 +136,114 @@ spec: - name: ASPNETCORE_URLS value: http://0.0.0.0:80/ordering-api - name: ConnectionString - value: "Server=sql-data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" + valueFrom: + configMapKeyRef: + name: externalcfg + key: OrderingSqlDb + - name: EventBusConnection + valueFrom: + configMapKeyRef: + name: externalcfg + key: OrderingBus + - name: AzureServiceBusEnabled + value: "true" + - name: IdentityUrl + valueFrom: + configMapKeyRef: + name: urls + key: IdentityUrl + ports: + - containerPort: 80 + imagePullSecrets: + - name: registry-key +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: locations +spec: + paused: true + template: + metadata: + labels: + app: eshop + component: locations + spec: + containers: + - name: locations + image: eshop/locations.api + imagePullPolicy: Always + env: + - name: ASPNETCORE_URLS + value: http://0.0.0.0:80/locations-api + - name: ConnectionString + valueFrom: + configMapKeyRef: + name: externalcfg + key: LocationsNoSqlDb + - name: Database + valueFrom: + configMapKeyRef: + name: externalcfg + key: LocationsNoSqlDbName + - name: AzureServiceBusEnabled + value: "true" + - name: EventBusConnection + valueFrom: + configMapKeyRef: + name: externalcfg + key: LocationsBus + - name: IdentityUrl + valueFrom: + configMapKeyRef: + name: urls + key: IdentityUrl + ports: + - containerPort: 80 + imagePullSecrets: + - name: registry-key +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: marketing +spec: + paused: true + template: + metadata: + labels: + app: eshop + component: marketing + spec: + containers: + - name: marketing + image: eshop/marketing.api + imagePullPolicy: Always + env: + - name: ASPNETCORE_URLS + value: http://0.0.0.0:80/marketing-api + - name: ConnectionString + valueFrom: + configMapKeyRef: + name: externalcfg + key: MarketingSqlDb + - name: MongoConnectionString + valueFrom: + configMapKeyRef: + name: externalcfg + key: MarketingNoSqlDb + - name: MongoDatabase + valueFrom: + configMapKeyRef: + name: externalcfg + key: MarketingNoSqlDbName + - name: AzureServiceBusEnabled + value: "true" - name: EventBusConnection - value: rabbitmq + valueFrom: + configMapKeyRef: + name: externalcfg + key: MarketingBus - name: IdentityUrl valueFrom: configMapKeyRef: @@ -139,6 +256,37 @@ spec: --- apiVersion: extensions/v1beta1 kind: Deployment +metadata: + name: payment +spec: + paused: true + template: + metadata: + labels: + app: eshop + component: payment + spec: + containers: + - name: payment + image: eshop/payment.api + imagePullPolicy: Always + env: + - name: ASPNETCORE_URLS + value: http://0.0.0.0:80/payment-api + - name: AzureServiceBusEnabled + value: ·true" + - name: EventBusConnection + valueFrom: + configMapKeyRef: + name: externalcfg + key: PaymentBus + ports: + - containerPort: 80 + imagePullSecrets: + - name: registry-key +--- +apiVersion: extensions/v1beta1 +kind: Deployment metadata: name: webmvc spec: diff --git a/k8s/eShopOnAzure.json b/k8s/eShopOnAzure.json new file mode 100644 index 000000000..8f2e01931 --- /dev/null +++ b/k8s/eShopOnAzure.json @@ -0,0 +1,28 @@ +{ + "sql": { + "catalog": "Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=catalogdb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", + "identity":"Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=identitydb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", + "ordering":"Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=orderingdb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", + "marketing":"Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=marketingdb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" + }, + "nosql": { + "locations": { + "constr": "mongodb://eshop-nosqlez55a72p6wm62:l8jMNoLHFXOijAvaVMjHeCwHK8gAR9SovuK86uCOvwfnMhuhwytPKByOPqrQrlsDz9RPFet2J6SzEbBQXLZokA==@eshop-nosqlez55a72p6wm62.documents.azure.com:10255/?ssl=true&replicaSet=globaldb", + "db": "LocationsDb" + }, + "marketing": { + "constr": "mongodb://eshop-nosqlez55a72p6wm62:l8jMNoLHFXOijAvaVMjHeCwHK8gAR9SovuK86uCOvwfnMhuhwytPKByOPqrQrlsDz9RPFet2J6SzEbBQXLZokA==@eshop-nosqlez55a72p6wm62.documents.azure.com:10255/?ssl=true&replicaSet=globaldb", + "db": "MarketingDb" + } + }, + "redis": { + "basket" : "eshopredisez55a72p6wm62.redis.cache.windows.net" + }, + "servicebus": { + "ordering": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Iv+cC7Wgwc8SCrE5AXrguRW6kRMk6vR7crTVBom5nPU=;EntityPath=eshop_event_bus", + "marketing": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Iv+cC7Wgwc8SCrE5AXrguRW6kRMk6vR7crTVBom5nPU=;EntityPath=eshop_event_bus", + "locations": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Iv+cC7Wgwc8SCrE5AXrguRW6kRMk6vR7crTVBom5nPU=;EntityPath=eshop_event_bus", + "payment": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Iv+cC7Wgwc8SCrE5AXrguRW6kRMk6vR7crTVBom5nPU=;EntityPath=eshop_event_bus", + "basket": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Iv+cC7Wgwc8SCrE5AXrguRW6kRMk6vR7crTVBom5nPU=;EntityPath=eshop_event_bus" + } +} \ No newline at end of file diff --git a/k8s/local.json b/k8s/local.json new file mode 100644 index 000000000..08203e92f --- /dev/null +++ b/k8s/local.json @@ -0,0 +1,27 @@ +{ + "sql": { + "catalog": "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word;", + "identity":"Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word;", + "ordering":"Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;", + "marketing":"Server=sql.data;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word;" + }, + "nosql": { + "locations": { + "constr": "mongodb://nosql.data", + "db": "LocationsDb" + }, + "marketing": { + "constr": "mongodb://nosql.data", + "db": "MarketingDb" + } + }, + "redis": { + "basket" : "basket.data" + }, + "servicebus": { + "ordering": "rabbitmq", + "marketing": "rabbitmq", + "locations": "rabbitmq", + "payment": "rabbitmq" + } +} \ No newline at end of file diff --git a/k8s/nginx.conf b/k8s/nginx.conf index 1f754a8cd..5fd39f609 100644 --- a/k8s/nginx.conf +++ b/k8s/nginx.conf @@ -71,6 +71,24 @@ http { proxy_set_header Host $host; } + location /marketing-api { + proxy_pass http://marketing; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /payment-api { + proxy_pass http://payment; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /location-api { + proxy_pass http://location; + proxy_redirect off; + proxy_set_header Host $host; + } + location / { proxy_pass http://webspa; proxy_redirect off; diff --git a/k8s/services.yaml b/k8s/services.yaml index 3c45806d3..02b73448a 100644 --- a/k8s/services.yaml +++ b/k8s/services.yaml @@ -56,6 +56,48 @@ spec: --- apiVersion: v1 kind: Service +metadata: + labels: + app: eshop + component: locations + name: locations +spec: + ports: + - port: 80 + selector: + app: eshop + component: locations +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: eshop + component: payment + name: payment +spec: + ports: + - port: 80 + selector: + app: eshop + component: payment +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: eshop + component: marketing + name: marketing +spec: + ports: + - port: 80 + selector: + app: eshop + component: marketing +--- +apiVersion: v1 +kind: Service metadata: labels: app: eshop @@ -94,4 +136,4 @@ spec: - port: 80 selector: app: eshop - component: webspa \ No newline at end of file + component: webspa