Skip to content
Snippets Groups Projects
Commit fbff9e3d authored by Lukáš Daubner's avatar Lukáš Daubner :radioactive:
Browse files

Added k8s

parent d047440e
No related branches found
No related tags found
No related merge requests found
Pipeline #120633 passed
@page "/" @page "/"
@inject HttpClient Http
<PageTitle>Index</PageTitle> <PageTitle>Index</PageTitle>
<h1>Hello, world!</h1> <h1>@hello, world!</h1>
Welcome to your new app. Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" /> <SurveyPrompt Title="How is Blazor working for you?" />
@code {
private string hello;
protected override async Task OnInitializedAsync()
{
hello = await Http.GetStringAsync("Hello");
}
}
\ No newline at end of file
using Demo.DockerDeployment.Server.Options;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace Demo.DockerDeployment.Server.Controllers
{
[ApiController]
[Route("[controller]")]
public class HelloController : ControllerBase
{
private readonly ILogger<WeatherForecastController> _logger;
private string _hello;
public HelloController(IOptions<HelloOptions> hello, ILogger<WeatherForecastController> logger)
{
_hello = hello?.Value?.Hello ?? "Hello!";
_logger = logger;
}
[HttpGet]
public string Get()
{
return _hello;
}
}
}
namespace Demo.DockerDeployment.Server.Options
{
public class HelloOptions
{
public string Hello { get; set; }
}
}
using Demo.DockerDeployment.Server; using Demo.DockerDeployment.Server;
using Demo.DockerDeployment.Server.Controllers;
using Demo.DockerDeployment.Server.Options;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the DI container.
// Default configuration priority: appsettings.json < appsettings.{environment}.json < secrets.json < environment variables
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages(); builder.Services.AddRazorPages();
// ":" is not supported in env, so "__" is used instead and it is automatically converted by dotnet.
// export DemoDockerDeployment_Database__ConnectionString="Data Source=(localdb)\ProjectsV13;Initial Catalog=master;Integrated Security=True;"
builder.Configuration.AddEnvironmentVariables(prefix: "DemoDockerDeployment_");
builder.Services.Configure<HelloOptions>("Hello", builder.Configuration);
builder.Services.AddDbContextFactory<WeatherDbContext>(options => builder.Services.AddDbContextFactory<WeatherDbContext>(options =>
options.UseSqlServer(@"Data Source=(localdb)\ProjectsV13;Initial Catalog=master;Integrated Security=True;")); options.UseSqlServer(builder.Configuration["Database:ConnectionString"]));
var app = builder.Build(); var app = builder.Build();
......
...@@ -2,4 +2,15 @@ ...@@ -2,4 +2,15 @@
1. Deploy database locally 1. Deploy database locally
* dotnet ef database update * dotnet ef database update
2. Add CI/CD pipeline 2. Add CI/CD pipeline
\ No newline at end of file * Changes to the pre-generated Dockerfile
3. Show Kubernetes
* install kubectl
* download cluster config yaml
* (optional) set default namespace
* add credentials for git image store
5. Deploy web app without server ``kubectl apply -f .``
4. Configuration
* Environment variables
* (ALTERNATIVE, not mentioned) config maps
* Secrets
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: pv179-deployment-demo-dep
labels:
app: pv179-deployment-demo
spec:
replicas: 2
selector:
matchLabels:
app: pv179-deployment-demo
template:
metadata:
labels:
app: pv179-deployment-demo
spec:
securityContext:
runAsUser: 1000
runAsNonRoot: true
containers:
- name: pv179-deployment-demo
image: registry.gitlab.ics.muni.cz:443/lukasd/demo.dockerdeployment/app:latest
ports:
- containerPort: 8000
env:
- name: DemoDockerDeployment_Hello
value: Tere
- name: DemoDockerDeployment_Database__ConnectionString
valueFrom:
secretKeyRef:
name: pv179-deployment-demo-secret
key: connectionString
# SEE: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
# kubectl create secret docker-registry regcred --docker-server=registry.gitlab.ics.muni.cz:443 --docker-username=410034@mail.muni.cz --docker-password=PASS --docker-email=410034@mail.muni.cz
imagePullSecrets:
- name: regcred
\ No newline at end of file
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pv179-deployment-demo-ingress
annotations:
kuberentes.io/ingress.class: "nginx"
kubernetes.io/tls-acme: "true"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
tls:
- hosts:
- "pv179-deployment-demo.dyn.cloud.e-infra.cz"
secretName: pv179-deployment-demo-dyn-clout-e-infra-cz-tls
rules:
- host: "pv179-deployment-demo.dyn.cloud.e-infra.cz"
http:
paths:
- backend:
service:
name: pv179-deployment-demo-svc
port:
number: 80
pathType: ImplementationSpecific
\ No newline at end of file
apiVersion: v1
kind: Secret
metadata:
name: pv179-deployment-demo-secret
data:
connectionString: "Data Source=(localdb)\ProjectsV13;Initial Catalog=master;Integrated Security=True;"
\ No newline at end of file
apiVersion: v1
kind: Service
metadata:
name: pv179-deployment-demo-svc
spec:
type: ClusterIP
ports:
- name: pv179-deployment-demo-port
port: 80
targetPort: 8000
selector:
app: pv179-deployment-demo
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment