Deploying ocelot to k8s

configuration to ocelot passed through a k8s volume
This commit is contained in:
Eduard Tomàs 2018-01-11 18:18:16 +01:00
parent e72ada31fb
commit ea4e0ed6e8
13 changed files with 202 additions and 21 deletions

View File

@ -221,9 +221,9 @@ services:
- "15672:15672" - "15672:15672"
- "5672:5672" - "5672:5672"
ocelotapigw: apigw:
environment: environment:
- ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_ENVIRONMENT=Development
ports: ports:
- "80" - "5200:80"

View File

@ -108,9 +108,8 @@ services:
rabbitmq: rabbitmq:
image: rabbitmq:3-management-alpine image: rabbitmq:3-management-alpine
ocelotapigw: apigw:
image: ocelotapigw image: eshop/ocelotapigw
build: build:
context: . context: .
dockerfile: src/Apigw/OcelotApiGw/Dockerfile dockerfile: src/Apigw/OcelotApiGw/Dockerfile

View File

@ -105,6 +105,7 @@ ExecKube -cmd 'delete deployments --all'
ExecKube -cmd 'delete services --all' ExecKube -cmd 'delete services --all'
ExecKube -cmd 'delete configmap urls' ExecKube -cmd 'delete configmap urls'
ExecKube -cmd 'delete configmap externalcfg' ExecKube -cmd 'delete configmap externalcfg'
ExecKube -cmd 'delete configmap ocelot'
# start sql, rabbitmq, frontend deployments # start sql, rabbitmq, frontend deployments
if ($deployInfrastructure) { if ($deployInfrastructure) {
@ -113,6 +114,12 @@ if ($deployInfrastructure) {
} }
Write-Host 'Deploying ocelot APIGW' -ForegroundColor Yellow
ExecKube "create configmap ocelot --from-file=ocelot/configuration.json"
ExecKube -cmd "apply -f ocelot/deployment.yaml"
ExecKube -cmd "apply -f ocelot/service.yaml"
Write-Host 'Deploying code deployments (Web APIs, Web apps, ...)' -ForegroundColor Yellow Write-Host 'Deploying code deployments (Web APIs, Web apps, ...)' -ForegroundColor Yellow
ExecKube -cmd 'create -f services.yaml' ExecKube -cmd 'create -f services.yaml'
@ -154,7 +161,6 @@ ExecKube -cmd 'create configmap urls `
ExecKube -cmd 'label configmap urls app=eshop' ExecKube -cmd 'label configmap urls app=eshop'
Write-Host "Deploying configuration from $configFile" -ForegroundColor Yellow Write-Host "Deploying configuration from $configFile" -ForegroundColor Yellow
ExecKube -cmd "create -f $configFile" ExecKube -cmd "create -f $configFile"
Write-Host "Creating deployments..." -ForegroundColor Yellow Write-Host "Creating deployments..." -ForegroundColor Yellow
@ -178,6 +184,7 @@ ExecKube -cmd 'set image deployments/payment payment=${registryPath}${dockerOrg}
ExecKube -cmd 'set image deployments/webmvc webmvc=${registryPath}${dockerOrg}/webmvc:$imageTag' ExecKube -cmd 'set image deployments/webmvc webmvc=${registryPath}${dockerOrg}/webmvc:$imageTag'
ExecKube -cmd 'set image deployments/webstatus webstatus=${registryPath}${dockerOrg}/webstatus:$imageTag' ExecKube -cmd 'set image deployments/webstatus webstatus=${registryPath}${dockerOrg}/webstatus:$imageTag'
ExecKube -cmd 'set image deployments/webspa webspa=${registryPath}${dockerOrg}/webspa:$imageTag' ExecKube -cmd 'set image deployments/webspa webspa=${registryPath}${dockerOrg}/webspa:$imageTag'
ExecKube -cmd 'set image deployments/ocelot ocelot=${registryPath}${dockerOrg}/ocelotapigw:$imageTag'
Write-Host "Execute rollout..." -ForegroundColor Yellow Write-Host "Execute rollout..." -ForegroundColor Yellow
ExecKube -cmd 'rollout resume deployments/basket' ExecKube -cmd 'rollout resume deployments/basket'
@ -190,6 +197,7 @@ ExecKube -cmd 'rollout resume deployments/payment'
ExecKube -cmd 'rollout resume deployments/webmvc' ExecKube -cmd 'rollout resume deployments/webmvc'
ExecKube -cmd 'rollout resume deployments/webstatus' ExecKube -cmd 'rollout resume deployments/webstatus'
ExecKube -cmd 'rollout resume deployments/webspa' ExecKube -cmd 'rollout resume deployments/webspa'
ExecKube -cmd 'rollout resume deployments/ocelot'
Write-Host "WebSPA is exposed at http://$externalDns, WebMVC at http://$externalDns/webmvc, WebStatus at http://$externalDns/webstatus" -ForegroundColor Yellow Write-Host "WebSPA is exposed at http://$externalDns, WebMVC at http://$externalDns/webmvc, WebStatus at http://$externalDns/webstatus" -ForegroundColor Yellow

View File

@ -13,11 +13,11 @@ spec:
paths: paths:
- path: /basket-api - path: /basket-api
backend: backend:
serviceName: basket serviceName: ocelot
servicePort: 80 servicePort: 80
- path: /catalog-api - path: /catalog-api
backend: backend:
serviceName: catalog serviceName: ocelot
servicePort: 80 servicePort: 80
- path: /identity - path: /identity
backend: backend:
@ -25,7 +25,7 @@ spec:
servicePort: 80 servicePort: 80
- path: /ordering-api - path: /ordering-api
backend: backend:
serviceName: ordering serviceName: ocelot
servicePort: 80 servicePort: 80
- path: /webmvc - path: /webmvc
backend: backend:
@ -41,11 +41,11 @@ spec:
servicePort: 80 servicePort: 80
- path: /payment-api - path: /payment-api
backend: backend:
serviceName: payment serviceName: ocelot
servicePort: 80 servicePort: 80
- path: /locations-api - path: /locations-api
backend: backend:
serviceName: locations serviceName: ocelot
servicePort: 80 servicePort: 80
- path: / - path: /
backend: backend:

View File

@ -0,0 +1,58 @@
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "ordering",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/ordering-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "basket",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/basket-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "catalog",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/catalog-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "marketing",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/marketing-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "payment",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/payment-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "locations",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/location-api/{everything}",
"UpstreamHttpMethod": []
}
],
"GlobalConfiguration": {
"RequestIdKey": "OcRequestId",
"AdministrationPath": "/administration"
}
}

View File

@ -0,0 +1,31 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ocelot
spec:
paused: true
template:
metadata:
labels:
app: eshop
component: ocelot
spec:
containers:
- name: ocelot
image: eshop/ocelotapigw
imagePullPolicy: Always
ports:
- containerPort: 80
volumeMounts:
- name: config
mountPath: /app/configuration
volumes:
- name: config
configMap:
name: ocelot
items:
- key: configuration.json
path: configuration.json
imagePullSecrets:
- name: registry-key

13
k8s/ocelot/service.yaml Normal file
View File

@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: eshop
component: ocelot
name: ocelot
spec:
ports:
- port: 80
selector:
app: eshop
component: ocelot

View File

@ -4,9 +4,8 @@ EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src WORKDIR /src
COPY *.sln ./
COPY src/Apigw/OcelotApiGw/OcelotApiGw.csproj src/Apigw/OcelotApiGw/ COPY src/Apigw/OcelotApiGw/OcelotApiGw.csproj src/Apigw/OcelotApiGw/
RUN dotnet restore RUN dotnet restore src/Apigw/OcelotApiGw/
COPY . . COPY . .
WORKDIR /src/src/Apigw/OcelotApiGw WORKDIR /src/src/Apigw/OcelotApiGw
RUN dotnet build -c Release -o /app RUN dotnet build -c Release -o /app

View File

@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="Ocelot" Version="2.0.10" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -19,6 +19,7 @@ namespace OcelotApiGw
public static IWebHost BuildWebHost(string[] args) => public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args) WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
} }

View File

@ -2,22 +2,33 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using CacheManager.Core;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
namespace OcelotApiGw namespace OcelotApiGw
{ {
public class Startup public class Startup
{ {
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 private readonly IConfiguration _cfg;
public void ConfigureServices(IServiceCollection services)
public Startup(IConfiguration configuration)
{ {
_cfg = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(_cfg);
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
if (env.IsDevelopment()) if (env.IsDevelopment())
@ -25,10 +36,7 @@ namespace OcelotApiGw
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
app.Run(async (context) => app.UseOcelot();
{
await context.Response.WriteAsync("Hello World!");
});
} }
} }
} }

View File

@ -0,0 +1,58 @@
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "ordering.api",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/orders-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "basket.api",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/basket-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "catalog.api",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/catalog-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "marketing.api",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/marketing-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "payment.api",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/payment-api/{everything}",
"UpstreamHttpMethod": []
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHost": "locations.api",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/location-api/{everything}",
"UpstreamHttpMethod": []
}
],
"GlobalConfiguration": {
"RequestIdKey": "OcRequestId",
"AdministrationPath": "/administration"
}
}

5
xglobal.json Normal file
View File

@ -0,0 +1,5 @@
{
"sdk": {
"version":"2.1.2"
}
}