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:
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:
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.
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.
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.
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.
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).
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.
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:
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:
Last May I wrote: Accepting Azure Marketplace Terms with Azure CLI and this time we’ll accomplish the same task with Ansible.
Turns out that Ansible 2.6 comes with a handy new module: azure_rm_resource which lets you create, update or delete any Azure resource using Azure REST API. So I decided to take it for a test drive with the “Accepting Terms” sample.
I’ve been using Ansible and the Azure CLI every single day for the last 3 months. Non stop work editing playbooks and scripts with Visual Studio Code and running them on Ubuntu (WSL) on my Windows 10 machine.
Turns out that because Ansible uses python version 2.7.12 and the Azure CLI uses python 3.6.5 you can make a mess if you get “creative” trying to install the tools instead of using the recommended commands:
For ages I’ve been waiting for a way to enforce netwok policies on AKS, so last weekend while I was googling around, I found this hidden gem posted by Marcus Robinson: Enforcing Network Policies using kube-router on AKS and had to test the proposed solution.
Prerequisites:
Azure Kubernetes Service (AKS) deployed with HTTP application routing enabled. kubectl installed Create a service exposed throuh your AKS DNS Zone # Let’s start by deploying the following service to your Kubernetes cluster, by saving the following content to a file named dni-function.yaml and replacing [YOUR_DNS__ZONE_NAME] with the corresponding value of your service:
I think that more than a year and a half ago I read “Real-World Machine Learning” by Henrik Brink, Joseph Richards, and Mark Fetherolf. A book that is easy to read and goes “to the point”!!! I’m sure you know what I mean.
At the time the only thing that prevented me from really enjoying the book samples was that there was no easy way to “translate” them to .NET Core.
When you try to deploy a VM from the Marketplace using an ARM (json) template you’ll get an error like the one below in the case when you’ve not previously accepted the Legal terms for the image:
[{"Legal terms have not been accepted for this item on this subscription. To accept terms using Powershell..."}] Accepting the Legal terms is something you have to do once per subscription for each provider offer you want to use. So how can you accept the terms using the Azure CLI (version 2.0.26 or higher)?
NOTE: The issue described in this post was fixed!!! (ansible 2.5.2 and Azure CLI 2.0.34) # Last week I tried to run this simple Ansible playbook in Azure Cloud Shell:
# resource_group.yml # Create test resource group in west europe - name: Create a Resource Group hosts: localhost connection: local gather_facts: no tasks: - name: Create Resource Group azure_rm_resourcegroup: location: westeurope name: test state: present The first attempt to run the playbook with:
Today I’ll show you how to use dotnet-addcasa: a .NET Core global tool to add CodeAnalysis and Stylecop checks to your projects.
If you want to manually add those checks or understand the tool internals check my post: .NET Core, Code Analysis and StyleCop
Prerequisites # You’ll need .NET Core SDK 2.1.300-preview1 installed.
Today I’ll show you how to create a simple Echo Server with ASP.NET Core and then a Docker Image using multi-stage build:
Create the Application # Open a PowerShell promt and run:
mkdir echoserver cd echoserver dotnet new console dotnet add package Microsoft.AspNetCore -v 2.0.2 Replace the contents of Program.cs # Replace the contents of the Program.cs file with the following code:
Disclaimer: samples provided in this post were tested both in Azure Container Services (AKS) and Kubernetes provided by Docker for Windows.
In previous posts I showed you how to Run a Precompiled .NET Core Azure Function in a Container and how to Deploy your first Service to Azure Container Services (AKS).
By now you should be able to run your own services in Kubernetes and starting to wonder about how can you give answers to questions such as:
This is a small kubectl Cheat Sheet with the list of commands and settings I use, almost on a daily basis, when working with kubernetes.
Get version and cluster information # Get kubectl version # kubectl --version Get cluster information # kubectl cluster-info Check cluster nodes # kubectl get nodes Get running services # kubectl get services -w --all-namespaces Context # List all available contexts # kubectl config get-contexts Get current context # kubectl config current-context Change the context # kubectl config use-context [context name] Deployment # Deploy # kubectl apply -f [yaml definition file] Get deployment definition # kubectl get deployment [deployment name] -o yaml Update the image of a deployment # kubectl set image deployment/[deployment name] [container name]=[image tag] Set autoscale for a deployment # kubectl autoscale deployment [deployment name] --min=2 --max=5 --cpu-percent=80 Delete a deployment # kubectl delete -f [yaml definition file] Get secret definition # kubectl get secret [secret name] -o yaml Force delete a pod # kubectl delete pod [pod name] --grace-period=0 --force Logs # Read a pod’s log # kubectl logs [pod name] -n [namespace name] Misc # Install kubernetes dashboard # kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml Hope it helps!