Deploying ocelot to k8s
configuration to ocelot passed through a k8s volume
This commit is contained in:
Родитель
e72ada31fb
Коммит
ea4e0ed6e8
|
@ -221,9 +221,9 @@ services:
|
|||
- "15672:15672"
|
||||
- "5672:5672"
|
||||
|
||||
ocelotapigw:
|
||||
apigw:
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=Development
|
||||
ports:
|
||||
- "80"
|
||||
- "5200:80"
|
||||
|
||||
|
|
|
@ -108,9 +108,8 @@ services:
|
|||
rabbitmq:
|
||||
image: rabbitmq:3-management-alpine
|
||||
|
||||
ocelotapigw:
|
||||
image: ocelotapigw
|
||||
apigw:
|
||||
image: eshop/ocelotapigw
|
||||
build:
|
||||
context: .
|
||||
dockerfile: src/Apigw/OcelotApiGw/Dockerfile
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ ExecKube -cmd 'delete deployments --all'
|
|||
ExecKube -cmd 'delete services --all'
|
||||
ExecKube -cmd 'delete configmap urls'
|
||||
ExecKube -cmd 'delete configmap externalcfg'
|
||||
ExecKube -cmd 'delete configmap ocelot'
|
||||
|
||||
# start sql, rabbitmq, frontend deployments
|
||||
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
|
||||
ExecKube -cmd 'create -f services.yaml'
|
||||
|
||||
|
@ -154,7 +161,6 @@ ExecKube -cmd 'create configmap urls `
|
|||
ExecKube -cmd 'label configmap urls app=eshop'
|
||||
|
||||
Write-Host "Deploying configuration from $configFile" -ForegroundColor Yellow
|
||||
|
||||
ExecKube -cmd "create -f $configFile"
|
||||
|
||||
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/webstatus webstatus=${registryPath}${dockerOrg}/webstatus:$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
|
||||
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/webstatus'
|
||||
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
|
||||
|
||||
|
|
|
@ -13,11 +13,11 @@ spec:
|
|||
paths:
|
||||
- path: /basket-api
|
||||
backend:
|
||||
serviceName: basket
|
||||
serviceName: ocelot
|
||||
servicePort: 80
|
||||
- path: /catalog-api
|
||||
backend:
|
||||
serviceName: catalog
|
||||
serviceName: ocelot
|
||||
servicePort: 80
|
||||
- path: /identity
|
||||
backend:
|
||||
|
@ -25,7 +25,7 @@ spec:
|
|||
servicePort: 80
|
||||
- path: /ordering-api
|
||||
backend:
|
||||
serviceName: ordering
|
||||
serviceName: ocelot
|
||||
servicePort: 80
|
||||
- path: /webmvc
|
||||
backend:
|
||||
|
@ -41,11 +41,11 @@ spec:
|
|||
servicePort: 80
|
||||
- path: /payment-api
|
||||
backend:
|
||||
serviceName: payment
|
||||
serviceName: ocelot
|
||||
servicePort: 80
|
||||
- path: /locations-api
|
||||
backend:
|
||||
serviceName: locations
|
||||
serviceName: ocelot
|
||||
servicePort: 80
|
||||
- path: /
|
||||
backend:
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -4,9 +4,8 @@ EXPOSE 80
|
|||
|
||||
FROM microsoft/aspnetcore-build:2.0 AS build
|
||||
WORKDIR /src
|
||||
COPY *.sln ./
|
||||
COPY src/Apigw/OcelotApiGw/OcelotApiGw.csproj src/Apigw/OcelotApiGw/
|
||||
RUN dotnet restore
|
||||
RUN dotnet restore src/Apigw/OcelotApiGw/
|
||||
COPY . .
|
||||
WORKDIR /src/src/Apigw/OcelotApiGw
|
||||
RUN dotnet build -c Release -o /app
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
|
||||
<PackageReference Include="Ocelot" Version="2.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace OcelotApiGw
|
|||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
}
|
||||
|
|
|
@ -2,22 +2,33 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CacheManager.Core;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Middleware;
|
||||
|
||||
namespace OcelotApiGw
|
||||
{
|
||||
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
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
|
||||
private readonly IConfiguration _cfg;
|
||||
|
||||
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)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
|
@ -25,10 +36,7 @@ namespace OcelotApiGw
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.Run(async (context) =>
|
||||
{
|
||||
await context.Response.WriteAsync("Hello World!");
|
||||
});
|
||||
app.UseOcelot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version":"2.1.2"
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче