Upgrade to Pro — share decks privately, control downloads, hide ads and more …

.NET Core Mikroservis Uygulamalarında Konfigürasyon Yönetimi

Selçuk Usta
September 04, 2018

.NET Core Mikroservis Uygulamalarında Konfigürasyon Yönetimi

Selçuk Usta

September 04, 2018
Tweet

More Decks by Selçuk Usta

Other Decks in Programming

Transcript

  1. ustasoglu /in/selcukusta selcukusta selcukusta.com selcukusta SELÇUK USTA Yazılım Mimarı @

    Demirören Medya Bilge Adam, Lynx S.p.A, Hürriyet, KoçSistem
  2. Ajanda ▪ Mikroservis mimarilerde "cross-cutting concerns" ▪ Concern#1 – Merkezi

    Konfigürasyon Yönetimi ▪ Spring Boot ▪ Hashicorp Vault ▪ Steeltoe Client Library ▪ Demo
  3. If you can’t build a monolith, what makes you think

    microservices are the answer? Simon Brown
  4. public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .ConfigureLogging(logging =>

    { logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); }) .UseNLog() .Build();
  5. public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddDistributedMemoryCache();

    services.AddSession(options => { options.IdleTimeout = TimeSpan.FromSeconds(10); options.Cookie.HttpOnly = true; }); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSession(); } }
  6. { "Services": { "ProductService": "http://192.168.1.101" } } public void ConfigureServices(IServiceCollection

    services) { var productServiceUrl = Configuration["Services:ProductService"]; } appsettings.json Startup.cs
  7. Problem Uygulama, herhangi bir modifikasyon ya da tekrar derleme gerektirmeden;

    ortam bağımlılığına göre konfigürasyon okuyabiliyor mu?
  8. { "ShowPromotedProducts" : true } public void ConfigureServices(IServiceCollection services) {

    var showPromotedProducts = Configuration.GetValue<bool>("ShowPromotedProducts"); } appsettings.Development.json Startup.cs
  9. GO Micro JAVA Spring Boot .NET ASP.NET Boilerplate Çözüm Her

    servis oluşturmada aynı implementasyonları tekrar tekrar yapmak yerine, servis şablonları oluşturmak/kullanmak
  10. Java, Kotlin ya da Groovy dilleriyle; Spring altyapısı ile güçlendirilmiş

    ve minimum geliştirme eforuyla production ortamına hazır servis ve uygulama şablonları oluşturulmasını sağlayan kütüphanedir. Bazı örnekler; - spring-boot-sample-data- elasticsearch - spring-boot-sample-data-ldap - spring-boot-sample-data- mongodb - spring-boot-sample-tomcat-ssl - spring-boot-sample-web-jsp - spring-boot-sample-websocket- tomcat
  11. Vault, Hashicorp tarafından geliştirilen; şifre, token, sertifika, API anahtarı gibi

    gizli bilgileri ya da uygulamalara özel konfigürasyon tanımlarını üzerinde saklayan ve RESTful servisi yardımıyla dışarıya servis eden bir uygulamadır. Bazı özellikleri; - Key rolling özelliği ile, tanımın tutulduğu anahtarın versiyonlanması ve T anında ilgili versiyona geri dönülmesi sağlanır. - Audit logları sayesinde, anahtarlar ve değerleri üzerinde yapılan değişiklikler; kullanıcı bazlı olarak kayıt altında tutulur. - Policy’ler ile, saklanan değerler üzerinde yapılacak operasyonlar sınırlandırılabilir.
  12. public static IVaultClient GetVaultClient(string token, string vaultUri) { IAuthMethodInfo authMethod

    = new TokenAuthMethodInfo(token); var vaultClientSettings = new VaultClientSettings(vaultUri, authMethod); IVaultClient vaultClient = new VaultSharp.VaultClient(vaultClientSettings); return vaultClient; } Create Vault client public static async Task WriteSecretAsync(IVaultClient client, string path, IDictionary<string, object> data) => await client.V1.Secrets.KeyValue.V2.WriteSecretAsync(path, data); Write secret public static async Task<Secret<SecretData>> ReadSecretAsync(IVaultClient client, string path) => await client.V1.Secrets.KeyValue.V2.ReadSecretAsync(path); Read secret
  13. Steeltoe, Pivotal tarafından geliştirilen; .NET tabanlı cloud-native mikroservis uygulamaları geliştirilmesine

    yardımcı fonksiyonaliteleri sağlayan, .NET Foundation çatısı altındaki kütüphanedir. Sağladığı bazı servisler; - Netflix Eureka tabanlı Service Discovery modülü, - Spring Cloud Config Server tabanlı Config Server modülü, - Netflix Hystrix tabanlı Circuit Breaker modülü - Pivotal Cloud Foundry (PCF) ürünü üzerinde tanımlı servis ve uygulamaların entegrasyonunda kullanılan Service Connectors modülü