Skip to content

Commit 5dd1ce2

Browse files
committed
Config files for k8s deployment of all services updated
1 parent 2ad4850 commit 5dd1ce2

7 files changed

Lines changed: 291 additions & 12 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ services:
108108
- rabbitmq
109109

110110
locations.api:
111-
image: locations.api
111+
image: eshop/locations.api
112112
build:
113113
context: ./src/Services/Location/Locations.API
114114
dockerfile: Dockerfile

global.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version":"1.0.4"
4+
}
5+
}

k8s/deploy.ps1

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ Param(
55
[parameter(Mandatory=$false)][bool]$deployCI,
66
[parameter(Mandatory=$false)][bool]$useDockerHub,
77
[parameter(Mandatory=$false)][string]$execPath,
8-
[parameter(Mandatory=$false)][string]$kubeconfigPath
8+
[parameter(Mandatory=$false)][string]$kubeconfigPath,
9+
[parameter(Mandatory=$true)][string]$configFile
910
)
1011

12+
$debugMode = $PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent
13+
1114
function ExecKube($cmd) {
1215
if($deployCI) {
1316
$kubeconfig = $kubeconfigPath + 'config';
@@ -20,6 +23,19 @@ function ExecKube($cmd) {
2023
}
2124
}
2225

26+
27+
$config = Get-Content -Raw -Path $configFile | ConvertFrom-Json
28+
29+
if ($debugMode) {
30+
Write-Host "Using following JSON config: "
31+
$json = ConvertTo-Json $config -Depth 5
32+
Write-Host $json
33+
Write-Host "Press a key "
34+
[System.Console]::Read()
35+
}
36+
37+
38+
2339
# Not used when deploying through CI VSTS
2440
if(-not $deployCI) {
2541
$requiredCommands = ("docker", "docker-compose", "kubectl")
@@ -54,11 +70,13 @@ ExecKube -cmd 'delete deployments --all'
5470
ExecKube -cmd 'delete services --all'
5571
ExecKube -cmd 'delete configmap config-files'
5672
ExecKube -cmd 'delete configmap urls'
73+
ExecKube -cmd 'delete configmap externalcfg'
5774

5875
# start sql, rabbitmq, frontend deploymentsExecKube -cmd 'delete configmap config-files'
5976
ExecKube -cmd 'create configmap config-files --from-file=nginx-conf=nginx.conf'
6077
ExecKube -cmd 'label configmap config-files app=eshop'
61-
ExecKube -cmd 'create -f sql-data.yaml -f basket-data.yaml -f keystore-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml'
78+
# ExecKube -cmd 'create -f sql-data.yaml -f basket-data.yaml -f keystore-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml'
79+
ExecKube -cmd 'create -f services.yaml -f frontend.yaml'
6280

6381
# building and publishing docker images not necessary when deploying through CI VSTS
6482
if(-not $deployCI) {
@@ -109,6 +127,27 @@ ExecKube -cmd 'create configmap urls `
109127

110128
ExecKube -cmd 'label configmap urls app=eshop'
111129

130+
Write-Host "Applying external configuration from json" -ForegroundColor Yellow
131+
132+
ExecKube -cmd 'create configmap externalcfg `
133+
--from-literal=CatalogSqlDb=$($config.sql.catalog) `
134+
--from-literal=IdentitySqlDb=$($config.sql.identity) `
135+
--from-literal=OrderingSqlDb=$($config.sql.ordering) `
136+
--from-literal=MarketingSqlDb=$($config.sql.marketing) `
137+
--from-literal=LocationsNoSqlDb=$($config.nosql.locations.constr) `
138+
--from-literal=LocationsNoSqlDbName=$($config.nosql.locations.db) `
139+
--from-literal=MarketingsNoSqlDb=$($config.nosql.marketing.constr) `
140+
--from-literal=MarketingNoSqlDbName=$($config.nosql.marketing.db) `
141+
--from-literal=BasketRedisConStr=$($config.redis.basket) `
142+
--from-literal=LocationsBus=$($config.servicebus.locations) `
143+
--from-literal=MarketingBus=$($config.servicebus.marketing) `
144+
--from-literal=BasketBus=$($config.servicebus.basket) `
145+
--from-literal=OrderingBus=$($config.servicebus.ordering) `
146+
--from-literal=PaymentBus=$($config.servicebus.payment) '
147+
148+
ExecKube -cmd 'label configmap externalcfg app=eshop'
149+
150+
112151
Write-Host "Creating deployments..." -ForegroundColor Yellow
113152

114153
ExecKube -cmd 'create -f deployments.yaml'

k8s/deployments.yaml

Lines changed: 156 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ spec:
1818
- name: ASPNETCORE_URLS
1919
value: http://0.0.0.0:80/basket-api
2020
- name: ConnectionString
21-
value: basket-data
21+
valueFrom:
22+
configMapKeyRef:
23+
name: externalcfg
24+
key: BasketRedisConStr
2225
- name: EventBusConnection
23-
value: rabbitmq
26+
valueFrom:
27+
configMapKeyRef:
28+
name: externalcfg
29+
key: BasketBus
30+
- name: AzureServiceBusEnabled
31+
value: "true"
2432
- name: IdentityUrl
2533
valueFrom:
2634
configMapKeyRef:
@@ -51,9 +59,10 @@ spec:
5159
- name: ASPNETCORE_URLS
5260
value: http://0.0.0.0:80/catalog-api
5361
- name: ConnectionString
54-
value: "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word"
55-
- name: EventBusConnection
56-
value: rabbitmq
62+
valueFrom:
63+
configMapKeyRef:
64+
name: externalcfg
65+
key: CatalogSqlDb
5766
- name: ExternalCatalogBaseUrl
5867
valueFrom:
5968
configMapKeyRef:
@@ -84,7 +93,10 @@ spec:
8493
- name: ASPNETCORE_URLS
8594
value: http://0.0.0.0:80/identity
8695
- name: ConnectionStrings__DefaultConnection
87-
value: "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word"
96+
valueFrom:
97+
configMapKeyRef:
98+
name: externalcfg
99+
key: IdentitySqlDb
88100
- name: DPConnectionString
89101
value: keystore-data
90102
- name: IsClusterEnv
@@ -124,9 +136,114 @@ spec:
124136
- name: ASPNETCORE_URLS
125137
value: http://0.0.0.0:80/ordering-api
126138
- name: ConnectionString
127-
value: "Server=sql-data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"
139+
valueFrom:
140+
configMapKeyRef:
141+
name: externalcfg
142+
key: OrderingSqlDb
143+
- name: EventBusConnection
144+
valueFrom:
145+
configMapKeyRef:
146+
name: externalcfg
147+
key: OrderingBus
148+
- name: AzureServiceBusEnabled
149+
value: "true"
150+
- name: IdentityUrl
151+
valueFrom:
152+
configMapKeyRef:
153+
name: urls
154+
key: IdentityUrl
155+
ports:
156+
- containerPort: 80
157+
imagePullSecrets:
158+
- name: registry-key
159+
---
160+
apiVersion: extensions/v1beta1
161+
kind: Deployment
162+
metadata:
163+
name: locations
164+
spec:
165+
paused: true
166+
template:
167+
metadata:
168+
labels:
169+
app: eshop
170+
component: locations
171+
spec:
172+
containers:
173+
- name: locations
174+
image: eshop/locations.api
175+
imagePullPolicy: Always
176+
env:
177+
- name: ASPNETCORE_URLS
178+
value: http://0.0.0.0:80/locations-api
179+
- name: ConnectionString
180+
valueFrom:
181+
configMapKeyRef:
182+
name: externalcfg
183+
key: LocationsNoSqlDb
184+
- name: Database
185+
valueFrom:
186+
configMapKeyRef:
187+
name: externalcfg
188+
key: LocationsNoSqlDbName
189+
- name: AzureServiceBusEnabled
190+
value: "true"
191+
- name: EventBusConnection
192+
valueFrom:
193+
configMapKeyRef:
194+
name: externalcfg
195+
key: LocationsBus
196+
- name: IdentityUrl
197+
valueFrom:
198+
configMapKeyRef:
199+
name: urls
200+
key: IdentityUrl
201+
ports:
202+
- containerPort: 80
203+
imagePullSecrets:
204+
- name: registry-key
205+
---
206+
apiVersion: extensions/v1beta1
207+
kind: Deployment
208+
metadata:
209+
name: marketing
210+
spec:
211+
paused: true
212+
template:
213+
metadata:
214+
labels:
215+
app: eshop
216+
component: marketing
217+
spec:
218+
containers:
219+
- name: marketing
220+
image: eshop/marketing.api
221+
imagePullPolicy: Always
222+
env:
223+
- name: ASPNETCORE_URLS
224+
value: http://0.0.0.0:80/marketing-api
225+
- name: ConnectionString
226+
valueFrom:
227+
configMapKeyRef:
228+
name: externalcfg
229+
key: MarketingSqlDb
230+
- name: MongoConnectionString
231+
valueFrom:
232+
configMapKeyRef:
233+
name: externalcfg
234+
key: MarketingNoSqlDb
235+
- name: MongoDatabase
236+
valueFrom:
237+
configMapKeyRef:
238+
name: externalcfg
239+
key: MarketingNoSqlDbName
240+
- name: AzureServiceBusEnabled
241+
value: "true"
128242
- name: EventBusConnection
129-
value: rabbitmq
243+
valueFrom:
244+
configMapKeyRef:
245+
name: externalcfg
246+
key: MarketingBus
130247
- name: IdentityUrl
131248
valueFrom:
132249
configMapKeyRef:
@@ -139,6 +256,37 @@ spec:
139256
---
140257
apiVersion: extensions/v1beta1
141258
kind: Deployment
259+
metadata:
260+
name: payment
261+
spec:
262+
paused: true
263+
template:
264+
metadata:
265+
labels:
266+
app: eshop
267+
component: payment
268+
spec:
269+
containers:
270+
- name: payment
271+
image: eshop/payment.api
272+
imagePullPolicy: Always
273+
env:
274+
- name: ASPNETCORE_URLS
275+
value: http://0.0.0.0:80/payment-api
276+
- name: AzureServiceBusEnabled
277+
value: ·true"
278+
- name: EventBusConnection
279+
valueFrom:
280+
configMapKeyRef:
281+
name: externalcfg
282+
key: PaymentBus
283+
ports:
284+
- containerPort: 80
285+
imagePullSecrets:
286+
- name: registry-key
287+
---
288+
apiVersion: extensions/v1beta1
289+
kind: Deployment
142290
metadata:
143291
name: webmvc
144292
spec:

k8s/local.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"sql": {
3+
"catalog": "Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word;",
4+
"identity":"Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word;",
5+
"ordering":"Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
6+
"marketing":"Server=sql.data;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word;"
7+
},
8+
"nosql": {
9+
"locations": {
10+
"constr": "mongodb://nosql.data",
11+
"db": "LocationsDb"
12+
},
13+
"marketing": {
14+
"constr": "mongodb://nosql.data",
15+
"db": "MarketingDb"
16+
}
17+
},
18+
"redis": {
19+
"basket" : "basket.data"
20+
},
21+
"servicebus": {
22+
"ordering": "rabbitmq",
23+
"marketing": "rabbitmq",
24+
"locations": "rabbitmq",
25+
"payment": "rabbitmq"
26+
}
27+
}

k8s/nginx.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ http {
7171
proxy_set_header Host $host;
7272
}
7373

74+
location /marketing-api {
75+
proxy_pass http://marketing;
76+
proxy_redirect off;
77+
proxy_set_header Host $host;
78+
}
79+
80+
location /payment-api {
81+
proxy_pass http://payment;
82+
proxy_redirect off;
83+
proxy_set_header Host $host;
84+
}
85+
86+
location /location-api {
87+
proxy_pass http://location;
88+
proxy_redirect off;
89+
proxy_set_header Host $host;
90+
}
91+
7492
location / {
7593
proxy_pass http://webspa;
7694
proxy_redirect off;

0 commit comments

Comments
 (0)