Browse Source

Deploying ocelot to k8s

configuration to ocelot passed through a k8s volume
pull/815/head
Eduard Tomàs 7 years ago
parent
commit
ea4e0ed6e8
13 changed files with 201 additions and 20 deletions
  1. +2
    -2
      docker-compose.override.yml
  2. +2
    -3
      docker-compose.yml
  3. +9
    -1
      k8s/deploy.ps1
  4. +5
    -5
      k8s/ingress.yaml
  5. +58
    -0
      k8s/ocelot/configuration.json
  6. +31
    -0
      k8s/ocelot/deployment.yaml
  7. +13
    -0
      k8s/ocelot/service.yaml
  8. +1
    -2
      src/Apigw/OcelotApiGw/Dockerfile
  9. +1
    -0
      src/Apigw/OcelotApiGw/OcelotApiGw.csproj
  10. +1
    -0
      src/Apigw/OcelotApiGw/Program.cs
  11. +15
    -7
      src/Apigw/OcelotApiGw/Startup.cs
  12. +58
    -0
      src/Apigw/OcelotApiGw/configuration/configuration.json
  13. +5
    -0
      xglobal.json

+ 2
- 2
docker-compose.override.yml View File

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

+ 2
- 3
docker-compose.yml View File

@ -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

+ 9
- 1
k8s/deploy.ps1 View File

@ -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

+ 5
- 5
k8s/ingress.yaml View File

@ -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:


+ 58
- 0
k8s/ocelot/configuration.json 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"
}
}

+ 31
- 0
k8s/ocelot/deployment.yaml 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
- 0
k8s/ocelot/service.yaml 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

+ 1
- 2
src/Apigw/OcelotApiGw/Dockerfile View File

@ -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


+ 1
- 0
src/Apigw/OcelotApiGw/OcelotApiGw.csproj View File

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

+ 1
- 0
src/Apigw/OcelotApiGw/Program.cs View File

@ -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();
}


+ 15
- 7
src/Apigw/OcelotApiGw/Startup.cs View File

@ -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
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();
}
}
}

+ 58
- 0
src/Apigw/OcelotApiGw/configuration/configuration.json 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
- 0
xglobal.json View File

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

Loading…
Cancel
Save