Blog
Kubernetes: Despliegue en Azure
·126 words·1 min
azure
kubernetes
aks
Durante el mes de Octubre tuve la suerte de grabar en LinkedIn Learning mi primer curso online sobre Kubernetes.
Aun me queda mucho por aprender y mejorar en este formato, ya que mientras grabas los cursos no recibes feedback inmediato como sà ocurre cuando das una charla o haces una presentación.
GitOps: Deploying apps in Azure Kubernetes Service (AKS) with Flux
·312 words·2 mins
azure
kubernetes
devops
git
gitops
aks
flux
Recently I learned about GitOps which is a way to manage your Kubernetes clusters and the applications you run on top using Git. The idea is that you can declaratively describe the desired state of your systems in Git and roll out changes as soon as merges occur.
You can immediately see the main benefits of such an approach: Your Git repositories become the single source of truth for both your infrastructure and application code, allowing the teams to increase productivity and stability (you get the Git log to audit changes).
Kured: Restart your Azure Kubernetes Service Nodes
·278 words·2 mins
azure
kubernetes
devops
aks
kured
Two weeks ago I got an email message from Microsoft Azure explaining that Azure Kubernetes Services had been patched but that I had to restart my nodes (reboot the clusters) to complete the operation.
The first thing you need to know is that, when things like this happens, the Azure platform creates a file called /var/run/reboot-required in each of the nodes of your cluster.
Visual Studio Code Remote Containers: Azure Blockchain
·390 words·2 mins
azure
devops
blockchain
truffle
ganache
nodejs
ethereum
visual studio code
After collaborating with the Azure Ansible container I decided to also develop a Developer Container for those who want or need to use the Azure Blockchain Development Kit for Ethereum to create smart contracts, taking away the burden of installing Python, Truffle, Ganache and NodeJS on your machine.
Once again I collaborated with Chuck Lantz and the container definition resulted in the following two files:
Visual Studio Code Remote Containers: Azure Ansible
·558 words·3 mins
azure
devops
ansible
visual studio code
Last year I was working on a project for deploying Azure services using Ansible, and let me tell you something: Back then a feature like Visual Studio Remote Containers would have helped us so much!
Why? Because just installing Visual Studio Code, the Remote Development Extension Pack, and Docker you have a killer combo that makes it possible to create a Development environment in a snap and share it with your source code.
Scale a Kubernetes Deployment with .NET Core
·351 words·2 mins
dotnet
kubernetes
devops
aspnetcore
Let’s start:
Create a folder for your new project # Open a command prompt an run:
mkdir kuberenetes.scale Create the project # cd kuberenetes.scale dotnet new api Add the references to KubernetesClient # dotnet add package KubernetesClient -v 1.5.18 dotnet restore Create a PodsController.cs with the following code # using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using k8s; using k8s.Models; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; namespace kubernetes.scale { [Route("api/[controller]")] [ApiController] public class PodsController : ControllerBase { private KubernetesClientConfiguration k8sConfig = null; public PodsController(IConfiguration config) { // Reading configuration to know if running inside a cluster or in local mode. var useKubeConfig = bool.Parse(config["UseKubeConfig"]); if (!useKubeConfig) { // Running inside a k8s cluser k8sConfig = KubernetesClientConfiguration.InClusterConfig(); } else { // Running on dev machine k8sConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile(); } } [HttpPatch("scale")] public IActionResult Scale([FromBody]ReplicaRequest request) { // Use the config object to create a client. using (var client = new Kubernetes(k8sConfig)) { // Create a json patch for the replicas var jsonPatch = new JsonPatchDocument<V1Scale>(); // Set the new number of repplcias jsonPatch.Replace(e => e.Spec.Replicas, request.Replicas); // Creat the patch var patch = new V1Patch(jsonPatch); // Patch the "minions" Deployment in the "default" namespace client.PatchNamespacedDeploymentScale(patch, request.Deployment, request.Namespace); return NoContent(); } } } public class ReplicaRequest { public string Deployment { get; set; } public string Namespace { get; set; } public int Replicas { get; set; } } } Replace the contents of the appsettings.Development.json file # Note the UseKubeConfig property is set to true.
ARM: Enable Container Monitoring Solution on an existing Log Analytics Workspace
·99 words·1 min
azure
arm
log analytics
Recently I had to update a bunch of Log Analytics Workspaces resources to enable the Container Monitoring Solution. So I came up with this ARM Template that I want to share with you:
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "LogAnalyticsWorkspaceName": { "type": "string", "metadata": { "description": "Log Analytics Workspace name" } } }, "variables": { "workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces/', parameters('LogAnalyticsWorkspaceName'))]", "containerSolutionName": "[concat(parameters('LogAnalyticsWorkspaceName'), '-containers')]" }, "resources": [ { "type": "Microsoft.OperationsManagement/solutions", "apiVersion": "2015-11-01-preview", "name": "[variables('containerSolutionName')]", "location": "[resourceGroup().location]", "plan": { "name": "[variables('containerSolutionName')]", "product": "[concat('OMSGallery/', 'ContainerInsights')]", "promotionCode": "", "publisher": "Microsoft" }, "properties": { "workspaceResourceId": "[variables('workspaceResourceId')]" } } ], "outputs": {} } Hope it helps!
Running the Global Azure Bootcamp Science Lab in Kubernetes
·73 words·1 min
kubernetes
azure
aks
global azure
Next Saturday the Global Azure Bootcamp will be celebrated all over the world and as in previous years their will be a Science Lab where we’ll try to discover a planet!!!. Isn’t that cool?
Well to make this fast you can run the Science Lab using Azure Container Instances following the instructions found here or you can use the following gist to run the workload in an existing kubernetes cluster:
AKS & Application Gateway: Expose more than one service in an ingress resource
·155 words·1 min
kubernetes
azure
aks
application gateway
waf
ingress
If you install the Azure Application Gateway Ingress Controller for your AKS clusters you may want to expose more than one service through the same Public IP just changing the url path. In order to make this work you must use the backend-path-prefix annotation.
In the following sample I create an ingress with the following behavior:
AKS: Persistent Volume with existing Storage Account
·457 words·3 mins
kubernetes
azure
aks
storage account
persistent volume
persistent volume claim
storage class
In order to deploy a Persistent Volume in your AKS cluster using an existing Storage Account you should take the following steps:
Create a Storage Class with a reference to the Storage Account. Create a Secret with the credentials used to access the Storage Account. Create a Persistent Volume with a reference to the Storage Class, the secret and the File Share. Create a Persistent Volume Claim with a reference to the volume by name. Use the following yaml as a template for the resources described above. Save the contents as aks-existing-storage-account-pv.yaml:
Kubernetes: Mount a file in your Pod using a ConfigMap
·275 words·2 mins
kubernetes
azure
config map
volume
Lately I’ve been learning Go and this week I started a side project named kube-sherlock. The purpose of this small program is to list any pod that does not have the labels that your organization requires.
For kube-sherlock I created a dockerfile were both the program (kube-sherlock) and the default configuration (config.yaml) are placed in the app folder:
Updated Step by step: Serilog with ASP.NET Core
·276 words·2 mins
dotnet
aspnetcore
serilog
Many of you come to my site to read the post Step by step: Serilog with ASP.NET Core which I wrote in 2016 and is completely out of date, so with this post I will show you how to setup Serilog to work with your ASP.NET Core 2.2 applications.
Create an ASP.NET Core project # md aspnet.serilog.sample cd aspnet.serilog.sample dotnet new mvc Add the following dependencies to your project # dotnet add package Serilog.AspNetCore dotnet add package Serilog.Extensions.Logging dotnet add package Serilog.Sinks.ColoredConsole Change your Program.cs file to look like the following # using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Serilog; using Serilog.Core; using Serilog.Events; namespace aspnet.serilog.sample { public class Program { public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .MinimumLevel.Debug() .WriteTo.ColoredConsole( LogEventLevel.Verbose, "{NewLine}{Timestamp:HH:mm:ss} [{Level}] ({CorrelationToken}) {Message}{NewLine}{Exception}") .CreateLogger(); try { CreateWebHostBuilder(args).Build().Run(); } finally { Log.CloseAndFlush(); } } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseSerilog() .UseStartup<Startup>(); } } Inject the logger to your services or controllers # Change the home controller and log some actions:
AKS: Configure TLS termination with the http application routing addon
·225 words·2 mins
kubernetes
azure
aks
nginx
ingress controller
When you install a AKS cluster you can configure it to deploy the http application routing addon or you you can update an existing cluster to deploy it.
Either way you end up with an NGINX Ingress Controller running, in the kube-system namespace of your cluster, with the following properties:
ingress-class: addon-http-application-routing annotations-prefix: nginx.ingress.kubernetes.io Does this means that you can use this controller for TLS termination? The answer is yes! And you can also use rate limits, and whitelisting as described in my post Secure your Kubernetes services with NGINX ingress controller, tls and more.
Prepare yourself to work in Cloud
·700 words·4 mins
azure
cloud
Nowadays it’s clear that IT trends such as serverless computing, containerization, cloud native apps, DevOps artificial intelligence, machine learning and both hybrid and multi-cloud solutions are becoming main stream or the “new normal”. All businesses, big or small, are looking for cloud experts with key skills in many of these hot trends. With serverless architectures, applications are separated into various individual functions which are triggered by different types of events. This changes the way we normally think about applications and also the way we must approach operations in terms of monitoring performance, tracing, scaling and high availability. Good knowledge of AWS Lambda, Azure Functions, Google Cloud Functions, and event-driven architectures are skills employers will be looking for.
Develop and build ASP.NET Core applications to run on Kubernetes with Draft
·385 words·2 mins
dotnet
kubernetes
azure
aks
azure container registry
aspnetcore
You start developing an ASP.NET Core application to run it in Kubernetes and suddenly you find yourself creating a docker file, building an image, pushing the image to a registry, creating both a deployment and a service definition for Kubernetes and you wonder if there is a tool out there to help you streamline the whole process.
Deploying Elastic Search, Fluentd, Kibana on AKS with Helm
·117 words·1 min
kubernetes
azure
aks
elastic search
kibana
fluentd
For my recent talk at .NET Conf Madrid I managed to install Elastic Search, Fluentd and Kibana (EFK) as a logging solution for the AKS cluster I used in my demos.
The fact is that such deployment was possible thanks to Tim Park and his post Logging with Fluentd, ElasticSearch, and Kibana (EFK) on Kubernetes on Azure where I learned that to effectively deploy EFK on AKS I would have to tweak the resource definitions found in the Kubernetes project.
Revisiting Docker Multi Stage Builds to build an ASP.NET Core Echo Server
·252 words·2 mins
dotnet
aspnetcore
docker
On April I wrote a post about Using Docker Multi Stage Builds to build an ASP.NET Core Echo Server and these days while preparing a talk, on CI/CD and kubernetes, I started to play with the simple sample I wrote back then.
Soon enough I noticed that with each docker build command I issued the dependencies for the echoserver were always restored, even if no changes were made to the project file (csproj).
Adding SourceLink to your .NET Core Library
·500 words·3 mins
dotnet
sourcelink
debugging
Last week I read this tweets from Maxime Rouiller (@MaximRouiller):
Are you an MVP with a #dotnetcore #nuget package? Are you looking for an easy blog post? I have something for you.
— Maxime Rouiller (@MaximRouiller) August 22, 2018 Actually, you're already using it. https://t.co/N5IaY6TGqQ
That project is freaking cool. We need more package author to use it.
.NET Core, BenchmarkDotNet: for vs foreach performance
·581 words·3 mins
dotnet
dotnet
So what is faster: looping through a List<> with for or with foreach?
Today I’ll show you how to use BenchmarkDotNet with .Net Core to answer that question.
Let’s start:
Create a folder for your new project # Open a command prompt an run:
.NET Core, BenchmarkDotNet and string compare performance
·489 words·3 mins
dotnet
dotnet
You have to choose between using string.compare or == to compare strings. How would you know which method performs faster?
Today I’ll show you how to use BenchmarkDotNet with .Net Core to answer that question.
Let’s start:
Create a folder for your new project # Open a command prompt an run: