├── .gitignore ├── Dockerfile ├── README.md ├── app ├── Controllers │ ├── InfoController.cs │ └── WeatherForecastController.cs ├── InfoModel.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── WeatherForecast.cs ├── app.csproj ├── appsettings.Development.json └── appsettings.json └── chart ├── Chart.yaml ├── production-values.yaml ├── templates ├── deployment.yaml └── service.yaml └── values.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.*~ 3 | project.lock.json 4 | .DS_Store 5 | *.pyc 6 | nupkg/ 7 | 8 | # Visual Studio Code 9 | .vscode 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.userosscache 15 | *.sln.docstates 16 | 17 | # Build results 18 | [Dd]ebug/ 19 | [Dd]ebugPublic/ 20 | [Rr]elease/ 21 | [Rr]eleases/ 22 | x64/ 23 | x86/ 24 | build/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Oo]ut/ 29 | msbuild.log 30 | msbuild.err 31 | msbuild.wrn -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine as build 2 | WORKDIR /app 3 | 4 | # copy csproj and restore 5 | COPY app/*.csproj ./aspnetapp/ 6 | RUN cd ./aspnetapp/ && dotnet restore 7 | 8 | # copy all files and build 9 | COPY app/. ./aspnetapp/ 10 | WORKDIR /app/aspnetapp 11 | RUN dotnet publish -c Release -o out 12 | 13 | 14 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine as runtime 15 | WORKDIR /app 16 | COPY --from=build /app/aspnetapp/out ./ 17 | ENTRYPOINT [ "dotnet", "app.dll" ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a sample used in [Run ASP.NET Core 3 on Kubernetes with Helm](https://dev.to/wolnikmarcin/run-asp-net-core-3-on-kubernetes-with-helm-1o01) article. 2 | -------------------------------------------------------------------------------- /app/Controllers/InfoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace app.Controllers 9 | { 10 | [ApiController] 11 | [Route("")] 12 | public class InfoController : ControllerBase 13 | { 14 | private readonly ILogger _logger; 15 | 16 | public InfoController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet] 22 | public InfoModel GetInfo() 23 | { 24 | return new InfoModel { AppEnvironment = GetEnvironmentVariable("APPENVIRONMENT"), AppHost = GetEnvironmentVariable("APPHOST") }; 25 | } 26 | 27 | private string GetEnvironmentVariable(string name) 28 | { 29 | _logger.LogInformation($"Getting environment variable '{name}'."); 30 | return Environment.GetEnvironmentVariable(name.ToLower()) ?? Environment.GetEnvironmentVariable(name.ToUpper()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace app.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class WeatherForecastController : ControllerBase 13 | { 14 | private static readonly string[] Summaries = new[] 15 | { 16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 17 | }; 18 | 19 | private readonly ILogger _logger; 20 | 21 | public WeatherForecastController(ILogger logger) 22 | { 23 | _logger = logger; 24 | } 25 | 26 | [HttpGet] 27 | public IEnumerable Get() 28 | { 29 | var rng = new Random(); 30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 31 | { 32 | Date = DateTime.Now.AddDays(index), 33 | TemperatureC = rng.Next(-20, 55), 34 | Summary = Summaries[rng.Next(Summaries.Length)] 35 | }) 36 | .ToArray(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/InfoModel.cs: -------------------------------------------------------------------------------- 1 | namespace app 2 | { 3 | public class InfoModel 4 | { 5 | public string AppEnvironment { get; set; } 6 | public string AppHost { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /app/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace app 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:22836", 8 | "sslPort": 44365 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "app": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.HttpsPolicy; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Microsoft.Extensions.Hosting; 12 | using Microsoft.Extensions.Logging; 13 | 14 | namespace app 15 | { 16 | public class Startup 17 | { 18 | public Startup(IConfiguration configuration) 19 | { 20 | Configuration = configuration; 21 | } 22 | 23 | public IConfiguration Configuration { get; } 24 | 25 | // This method gets called by the runtime. Use this method to add services to the container. 26 | public void ConfigureServices(IServiceCollection services) 27 | { 28 | services.AddControllers(); 29 | } 30 | 31 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 32 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 33 | { 34 | if (env.IsDevelopment()) 35 | { 36 | app.UseDeveloperExceptionPage(); 37 | } 38 | 39 | app.UseHttpsRedirection(); 40 | 41 | app.UseRouting(); 42 | 43 | app.UseAuthorization(); 44 | 45 | app.UseEndpoints(endpoints => 46 | { 47 | endpoints.MapControllers(); 48 | }); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace app 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/app.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /app/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /chart/Chart.yaml: -------------------------------------------------------------------------------- 1 | name: aspnet3-demo 2 | version: 1.0.0 -------------------------------------------------------------------------------- /chart/production-values.yaml: -------------------------------------------------------------------------------- 1 | environment: production 2 | replicas: 5 3 | -------------------------------------------------------------------------------- /chart/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ .Release.Name }}-deployment 5 | labels: 6 | app: {{ .Values.label.name }} 7 | spec: 8 | replicas: {{ .Values.replicas }} 9 | selector: 10 | matchLabels: 11 | app: {{ .Values.label.name }} 12 | template: 13 | metadata: 14 | labels: 15 | app: {{ .Values.label.name }} 16 | environment: {{ .Values.environment }} 17 | spec: 18 | containers: 19 | - name: {{ .Values.container.name }} 20 | image: {{ .Values.container.image }}:{{ .Values.container.tag }} 21 | imagePullPolicy: {{ .Values.container.pullPolicy }} 22 | ports: 23 | - containerPort: {{ .Values.container.port }} 24 | env: 25 | - name: apphost 26 | value: {{ .Values.apphost }} 27 | - name: appenvironment 28 | value: {{ .Values.environment}} 29 | 30 | -------------------------------------------------------------------------------- /chart/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ .Release.Name }}-service 5 | labels: 6 | app: {{ .Values.label.name }} 7 | spec: 8 | ports: 9 | - port: {{ .Values.service.port}} 10 | protocol: TCP 11 | targetPort: {{ .Values.container.port }} 12 | selector: 13 | app: {{ .Values.label.name }} 14 | type: {{ .Values.service.type }} 15 | -------------------------------------------------------------------------------- /chart/values.yaml: -------------------------------------------------------------------------------- 1 | environment: development 2 | 3 | apphost: k8s 4 | 5 | label: 6 | name: aspnet3core 7 | 8 | container: 9 | name: aspnet3 10 | pullPolicy: IfNotPresent 11 | image: aspnet3k8s 12 | tag: v1 13 | port: 80 14 | 15 | replicas: 3 16 | 17 | service: 18 | port: 8888 19 | type: ClusterIP 20 | --------------------------------------------------------------------------------