Skip to content

Commit 4fe02d9

Browse files
committed
k8s deployment
config moved from custom json to standard k8s yaml
1 parent c997fe0 commit 4fe02d9

8 files changed

Lines changed: 131 additions & 101 deletions

File tree

README.k8s.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The script accepts following parameters:
4545
+ `dockerPassword`: Password to use for the Docker registry (if needed)
4646
+ `execPath`: Location of `kubectl` (if not in the path). If passed must finish with the path character.
4747
+ `kubeconfigPath`: Location of the `kubectl` configuration file. **This parameter is used only in the CI pipeline**, so you don't need to pass it when invoking the script using the CLI.
48-
+ `configFile`: Location of the JSON file with the configuration of the pods. **This parameter is mandatory**
48+
+ `configFile`: Location of the Yaml file with the `externalcfg` configmap to be deployed. This configmap is used to configure the Pod's environment **This parameter is mandatory**
4949
+ `imageTag`: Tag of the images to deploy to k8s. If not passed the name of the current branch is used.
5050
+ `externalDns`: External DNS name of the k8s. This is only needed if you have configured a DNS that points to your k8s external IP. If you don't have any DNS configured do not pass this parameter.
5151
+ `deployCI`: If `true` means that script is running under the context of a VSTS Hosted Build Agent. **You should never use this parameter from CLI**
@@ -56,20 +56,20 @@ The script accepts following parameters:
5656
5757
### Typical usages of the script:
5858
59-
Build all projects, and deploy all them in k8s including infrastructure containers in a organization called `foo` in Docker Hub. Images will be tagged with my current git branch and containers will use the configuration set in `local.json` file:
59+
Build all projects, and deploy all them in k8s including infrastructure containers in a organization called `foo` in Docker Hub. Images will be tagged with my current git branch and containers will use the configuration set in `conf_local.yml` file:
6060
6161
```
62-
./deploy.ps1 -buildBits $true -dockerOrg foo -dockerUser MY_USER -dockerPassword MY_PASSWORD -configFile local.json
62+
./deploy.ps1 -buildBits $true -dockerOrg foo -dockerUser MY_USER -dockerPassword MY_PASSWORD -configFile conf_local.yml
6363
```
6464
65-
Do not build any project and don't rebuild docker images. Create k8s deployments that will pull images from my private repository, in the `foo` organization, using the tag `latest`. Containers will use the configuration set in `cloud.json` file.
65+
Do not build any project and don't rebuild docker images. Create k8s deployments that will pull images from my private repository, in the `foo` organization, using the tag `latest`. Containers will use the configuration set in `conf_cloud` file.
6666
6767
```
68-
./deploy.ps1 -buildImages false -dockerOrg foo -registry MY_REGISTRY_FQDN -dockerUser MY_USER -dockerPassword MY_PASSWORD -configFile cloud.json -imageTag master
68+
./deploy.ps1 -buildImages $false -dockerOrg foo -registry MY_REGISTRY_FQDN -dockerUser MY_USER -dockerPassword MY_PASSWORD -configFile conf_cloud.yml -imageTag master
6969
```
7070
7171
Deploy k8s using public images that Microsoft provides:
7272
7373
```
74-
./deploy.ps1 -buildImages false --configFile local.json -imageTag master
74+
./deploy.ps1 -buildImages $false -configFile conf_local.yml -imageTag master
7575
```

k8s/cloud.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

k8s/conf_cloud.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: externalcfg
5+
labels:
6+
app: eshop
7+
data:
8+
# Basket.API entries
9+
BasketBus: CONNECTION_STRING (NAME OF RABBITMQ CONTAINER OR Endpoint=sb://XXXX in case of using Azure)
10+
BasketRedisConStr: REDIS CONNECTION STRING FOR BASKET
11+
# Catalog.API entries
12+
CatalogBus: CONNECTION_STRING (NAME OF RABBITMQ CONTAINER OR Endpoint=sb://XXXX in case of using Azure)
13+
CatalogSqlDb: Catalog SQL SERVER CONNECTION STRING (Server=xxxx;Intial Catalog=yyy;....)
14+
# Identity.API entries
15+
IdentitySqlDb: Identity SQL SERVER CONNECTION STRING (Server=xxxx;Intial Catalog=yyy;....)
16+
# Locations.API entries
17+
LocationsBus: CONNECTION_STRING (NAME OF RABBITMQ CONTAINER OR Endpoint=sb://XXXX in case of using Azure)
18+
LocationsNoSqlDb: Locations MongoDb ConnectionString
19+
LocationsNoSqlDbName: Locations MongoDb database (LocationsDb)
20+
# Marketing.API entries
21+
MarketingBus: CONNECTION_STRING (NAME OF RABBITMQ CONTAINER OR Endpoint=sb://XXXX in case of using Azure)
22+
MarketingNoSqlDb: Marketing MongoDb ConnectionString
23+
MarketingNoSqlDbName: Marketing MongoDb database (MarketingDb)
24+
MarketingSqlDb: Marketing SQL SERVER CONNECTION STRING (Server=xxxx;Intial Catalog=yyy;....)
25+
# Ordering.API entries
26+
OrderingBus: CONNECTION_STRING (NAME OF RABBITMQ CONTAINER OR Endpoint=sb://XXXX in case of using Azure)
27+
OrderingSqlDb: Ordering SQL SERVER CONNECTION STRING (Server=xxxx;Intial Catalog=yyy;....)
28+
# Payment.API entries
29+
PaymentBus: CONNECTION_STRING (NAME OF RABBITMQ CONTAINER OR Endpoint=sb://XXXX in case of using Azure)
30+
# GracePeriodManager entries
31+
GracePeriodTime: "5" # Grace period duration (time when you can cancel order) in minutes
32+
GracePeriodCheckUpdateTime: "60000" # Interval time to check new Order status (in milliseconds)
33+
# Global entries
34+
UseAzureServiceBus: "TRUE" IF USE AZURE SB ("FALSE" FOR USING RABBITMQ)
35+
keystore: REDIS CONNECTION STRING FOR KEYSTORE

k8s/conf_local.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: externalcfg
5+
labels:
6+
app: eshop
7+
data:
8+
BasketBus: rabbitmq
9+
BasketRedisConStr: basket-data
10+
CatalogBus: rabbitmq
11+
CatalogSqlDb: Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word;
12+
IdentitySqlDb: Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word;
13+
LocationsBus: rabbitmq
14+
LocationsNoSqlDb: mongodb://nosql-data
15+
LocationsNoSqlDbName: LocationsDb
16+
MarketingBus: rabbitmq
17+
MarketingNoSqlDb: mongodb://nosql-data
18+
MarketingNoSqlDbName: MarketingDb
19+
MarketingSqlDb: Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word;
20+
OrderingBus: rabbitmq
21+
OrderingSqlDb: Server=sql-data;Initial Catalog=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;
22+
PaymentBus: rabbitmq
23+
GracePeriodTime: "1"
24+
GracePeriodCheckUpdateTime: "60000"
25+
UseAzureServiceBus: "False"
26+
keystore: keystore-data

k8s/deploy.ps1

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ if ([string]::IsNullOrEmpty($imageTag)) {
5151
}
5252
Write-Host "Docker image Tag: $imageTag" -ForegroundColor Yellow
5353

54-
# Read config to use
55-
$config = Get-Content -Raw -Path $configFile | ConvertFrom-Json
56-
if ($debugMode) {
57-
Write-Host "[DEBUG]: Using following JSON config: " -ForegroundColor Yellow
58-
$json = ConvertTo-Json $config -Depth 5
59-
Write-Host $json
60-
if (-not $deployCI) {
61-
Write-Host "[DEBUG]: Press a key " -ForegroundColor Yellow
62-
[System.Console]::Read()
63-
}
64-
}
65-
6654
# building and publishing docker images if needed
6755
if($buildBits) {
6856
Write-Host "Building and publishing eShopOnContainers..." -ForegroundColor Yellow
@@ -166,27 +154,9 @@ ExecKube -cmd 'create configmap urls `
166154

167155
ExecKube -cmd 'label configmap urls app=eshop'
168156

169-
Write-Host "Applying external configuration from json" -ForegroundColor Yellow
170-
171-
ExecKube -cmd 'create configmap externalcfg `
172-
--from-literal=CatalogSqlDb=$($config.sql.catalog) `
173-
--from-literal=IdentitySqlDb=$($config.sql.identity) `
174-
--from-literal=OrderingSqlDb=$($config.sql.ordering) `
175-
--from-literal=MarketingSqlDb=$($config.sql.marketing) `
176-
--from-literal=LocationsNoSqlDb=$($config.nosql.locations.constr) `
177-
--from-literal=LocationsNoSqlDbName=$($config.nosql.locations.db) `
178-
--from-literal=MarketingNoSqlDb=$($config.nosql.marketing.constr) `
179-
--from-literal=MarketingNoSqlDbName=$($config.nosql.marketing.db) `
180-
--from-literal=BasketRedisConStr=$($config.redis.basket) `
181-
--from-literal=LocationsBus=$($config.servicebus.locations) `
182-
--from-literal=MarketingBus=$($config.servicebus.marketing) `
183-
--from-literal=BasketBus=$($config.servicebus.basket) `
184-
--from-literal=OrderingBus=$($config.servicebus.ordering) `
185-
--from-literal=CatalogBus=$($config.servicebus.catalog) `
186-
--from-literal=PaymentBus=$($config.servicebus.payment) `
187-
--from-literal=UseAzureServiceBus=$($config.servicebus.use_azure) `
188-
--from-literal=keystore=$($config.redis.keystore) '
189-
ExecKube -cmd 'label configmap externalcfg app=eshop'
157+
Write-Host "Deploying configuration from $configFile" -ForegroundColor Yellow
158+
159+
ExecKube -cmd "create -f $configFile"
190160

191161
Write-Host "Creating deployments..." -ForegroundColor Yellow
192162
ExecKube -cmd 'create -f deployments.yaml'

k8s/deployments.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,53 @@ spec:
173173
---
174174
apiVersion: extensions/v1beta1
175175
kind: Deployment
176+
metadata:
177+
name: graceperiodmanager
178+
spec:
179+
paused: true
180+
template:
181+
metadata:
182+
labels:
183+
app: graceperiodmanager
184+
component: ordering
185+
spec:
186+
containers:
187+
- name: graceperiodmanager
188+
image: eshop/graceperiodmanager
189+
imagePullPolicy: Always
190+
env:
191+
- name: ConnectionString
192+
valueFrom:
193+
configMapKeyRef:
194+
name: externalcfg
195+
key: OrderingSqlDb
196+
- name: EventBusConnection
197+
valueFrom:
198+
configMapKeyRef:
199+
name: externalcfg
200+
key: GracePeriodManagerBus
201+
- name: GracePeriodTime
202+
valueFrom:
203+
configMapKeyRef:
204+
name: externalcfg
205+
key: GracePeriodTime
206+
- name: CheckUpdateTime
207+
valueFrom:
208+
configMapKeyRef:
209+
name: externalcfg
210+
key: GracePeriodCheckUpdateTime
211+
- name: AzureServiceBusEnabled
212+
valueFrom:
213+
configMapKeyRef:
214+
name: externalcfg
215+
key: UseAzureServiceBus
216+
ports:
217+
- containerPort: 80
218+
imagePullSecrets:
219+
- name: registry-key
220+
---
221+
apiVersion: extensions/v1beta1
222+
kind: Deployment
176223
metadata:
177224
name: locations
178225
spec:

k8s/local.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

k8s/services.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ spec:
5656
---
5757
apiVersion: v1
5858
kind: Service
59+
metadata:
60+
labels:
61+
app: eshop
62+
component: graceperiodmanager
63+
name: graceperiodmanager
64+
spec:
65+
ports:
66+
- port: 80
67+
selector:
68+
app: eshop
69+
component: graceperiodmanager
70+
---
71+
apiVersion: v1
72+
kind: Service
5973
metadata:
6074
labels:
6175
app: eshop

0 commit comments

Comments
 (0)