-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1640 Combine Kubernetes ingress controller into a single deployable
#1640 Simplify packaging for Kubernetes
- Loading branch information
Showing
229 changed files
with
839 additions
and
108,112 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Rest; | ||
using Serilog; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace Yarp.Kubernetes.Ingress | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
using var serilog = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(theme: AnsiConsoleTheme.Code) | ||
.CreateLogger(); | ||
|
||
ServiceClientTracing.IsEnabled = true; | ||
|
||
Host.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(config => | ||
{ | ||
config.AddJsonFile("/app/config/yarp.json", optional: true); | ||
}) | ||
.ConfigureLogging(logging => | ||
{ | ||
logging.ClearProviders(); | ||
logging.AddSerilog(serilog, dispose: false); | ||
}) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}).Build().Run(); | ||
} | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
...Controller/Properties/launchSettings.json → ...e/Combined/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Yarp Ingress Controller | ||
|
||
This directory contains a sample ingress as well as the definition for the Kubernetes manifests for the ingress controller. | ||
|
||
The sample ingress controller is a single deployable (previously this was two separate deployables). | ||
|
||
## Building the Docker Image | ||
|
||
From the base directory for this repo (where the .sln file is), run the command: | ||
|
||
``` | ||
docker build -t yarp-combined:latest -f .\samples\KuberenetesIngress.Sample\Combined\Dockerfile . | ||
``` | ||
|
||
## Deploying the Sample Ingress Controller | ||
|
||
1. Open the [ingress-controller.yaml](./ingress-controller.yaml) file | ||
2. Modify the container image to match the name used when building the image, e.g. change `<REGISTRY_NAME>/yarp:<TAG>` to `yarp:latest` | ||
3. From the root of this repo. run the command `kubectl apply -f .\samples\KuberenetesIngress.Sample\Combined\ingress-controller.yaml` | ||
|
||
To undeploy the ingress controller, run the command `kubectl delete -f .\samples\KuberenetesIngress.Sample\Combined\ingress-controller.yaml` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Yarp.Kubernetes.Ingress | ||
{ | ||
public class Startup | ||
{ | ||
private readonly IConfiguration _configuration; | ||
|
||
public Startup(IConfiguration configuration) | ||
{ | ||
_configuration = configuration; | ||
} | ||
|
||
// 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) | ||
{ | ||
services.AddKubernetesReverseProxy(_configuration); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
#pragma warning disable CA1822 // Mark members as static | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
#pragma warning restore CA1822 // Mark members as static | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapReverseProxy(); | ||
}); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
samples/KuberenetesIngress.Sample/Combined/Yarp.Kubernetes.IngressController.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<UserSecretsId>78d1f3b4-abce-4c5a-b914-3321fab1f8d0</UserSecretsId> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<IsPackable>$('System.TeamProject') != 'internal'</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" /> | ||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" /> | ||
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Kubernetes.Controller\Yarp.Kubernetes.Controller.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
samples/KuberenetesIngress.Sample/Combined/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"Yarp": { | ||
"ControllerClass": "microsoft.com/ingress-yarp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
# Yarp Ingress and Ingress Controller | ||
# Yarp Ingress Controller | ||
|
||
This directory contains a sample ingress as well as the definition for the Kubernetes manifests for the ingress and ingress controller. | ||
This directory contains a sample ingress as well as the definition for the Kubernetes manifests for the ingress controller. | ||
|
||
This sample requires two applications to be deployed: | ||
* An Ingress (this application) | ||
* A Kubernetes Ingress Monitor () | ||
|
||
NOTE: Yarp Kubernetes can also be configured as a combined (single) deployable. See the combined [README.md](../Combined/README.md) for more information. | ||
|
||
## Building the Docker Images | ||
|
||
From the base directory for this repo (where the .sln file is), run the commands: | ||
|
||
``` | ||
docker build -t yarp-monitor:latest -f .\samples\KuberenetesIngress.Sample\Monitor\Dockerfile . | ||
docker build -t yarp-ingress:latest -f .\samples\KuberenetesIngress.Sample\Ingress\Dockerfile . | ||
``` | ||
|
||
## Deploying the Sample Ingress Controller | ||
|
||
1. Open the [ingress-monitor.yaml](../Monitor/ingress-monitor.yaml) file | ||
1. Modify the container image to match the name used when building the image, e.g. change `<REGISTRY_NAME>/yarp-monitor:<TAG>` to `yarp-monitor:latest` | ||
1. Run the command `kubectl apply -f .\samples\KuberenetesIngress.Sample\Monitor\ingress-monitor.yaml` | ||
1. Open the [ingress.yaml](./ingress.yaml) file | ||
1. Modify the container image to match the name used when building the image, e.g. change `<REGISTRY_NAME>/yarp-ingress:<TAG>` to `yarp-ingress:latest` | ||
1. Run the command `kubectl apply -f .\samples\KuberenetesIngress.Sample\Ingress\ingress.yaml` | ||
|
||
To undeploy the ingress, run the commands | ||
``` | ||
kubectl delete -f .\samples\KuberenetesIngress.Sample\Ingress\ingress.yaml | ||
kubectl delete -f .\samples\KuberenetesIngress.Sample\Monitor\ingress-monitor.yaml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
EXPOSE 443 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:6.0.100 AS publish | ||
WORKDIR /src | ||
|
||
# Copy csproj files and other files needed for restoring (to build a nuget cache layer to speed up rebuilds) | ||
COPY ["samples/KuberenetesIngress.Sample/Monitor/Yarp.Kubernetes.Monitor.csproj", "samples/KuberenetesIngress.Sample/Monitor/"] | ||
COPY ["src/ReverseProxy/Yarp.ReverseProxy.csproj", "src/ReverseProxy/"] | ||
COPY ["src/Kubernetes.Controller/Yarp.Kubernetes.Controller.csproj", "src/Kubernetes.Controller/"] | ||
COPY ["src/Directory.Build.props", "src/"] | ||
COPY ["Directory.Build.*", "./"] | ||
COPY ["global.json", ""] | ||
COPY ["NuGet.config", ""] | ||
|
||
# Build a cache layer with all of the nuget packages | ||
RUN dotnet restore samples/KuberenetesIngress.Sample/Monitor/Yarp.Kubernetes.Monitor.csproj | ||
|
||
# Copy the remaining source files | ||
WORKDIR /src | ||
COPY . . | ||
|
||
WORKDIR /src/samples/KuberenetesIngress.Sample/Monitor/ | ||
RUN dotnet publish -c Release --no-restore -o /app/publish -f net6.0 | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Yarp.Kubernetes.Monitor.dll"] |
Oops, something went wrong.