Coding Practice
Over the past month I’ve been practicing for the CKA (Certified Kubernetes Administrator) exam. I have my own homelab and have been wokring through the CKA course on udemy. After a lot of studying, the main thing that helps out is to practice. You know what they say - Practice makes Perfect!
However, this got me thinking - how do we keep our skills tuned when we often go for a certain amount of time without using them? How often do we write authorization packages? Normally, this happens at the beginning of a project/inital creation of a piece of software. If you write a lot of small simple applications you will do this quite often. Most of us do not have that luxury. Our skills get stale.
In order to combat, this I’m trying to write a simple application which will focus on a particular skill or software integration. One week, we can do an initial IAM setup. Then ext week, we can do a NoSQL integration. The following week, our practice application can be encryption/decryption as a service integration with vault. Every week we can tackle a different type of problem and see where we get.
Initial Project setups
So what are the important things we need to do when we first set a project. All of our projects shall focus on .NET 5, because why not be bleeding edge, and will focus on cloud development technologies. Each of these should be quick and fast - almost a review. Each item should also focus directly on one thing - you can even think of them as microservices. In no way shall this be considered production worthy code - copy pasta will always come back to haunt you.
Required Software
We will try to make this as system agnostic as possible. Therefore we shall try to focus on everything being built on containers and running on docker. Our first practice will be to create a simple WebApi in Visual Studio Code with C# deployed out to a container that we can run in docker (or whatever your Container Runtime of choice is). Each individual software practice will be based on a particular skill.
- Visual Studio Code
- Docker
- Open Source Software
Base project setup
So let’s get started. Let’s ensure that we have Visual Studio Code installed. We are going to start by following the Microsoft guide to creating a base project in Visual Studio Code with .NET 5 and C#. Ensure that you have the .NET 5 SDK installed and that you have Visual Studio code installed.
Go ahead and create a Practice Sessions Folder. Inside of Visual Studio Code open that directory. You will then open up a terminal window inside of Visual Studio code and run the following:
dotnet new webapi -o pttc.practice.api
This will go and create a new webApi project for dot net and set up the basic structure that you need. You can then go and change directories into the project and add in an Entity Framework in memory database with the following:
cd pttc.practice.api
dotnet add package Microsoft.EntityFrameworkCore.InMemory
This will pull in the nuget package for the in memory database provider for entity framework. Eventually, we will get into using actual databases, but this gets us up and running quickly with no additional setup work. We can then go and compile/run the project with the code command.
code -r ../pttc.practice.api
This compilation step will also go and ask to add additional assests to the project. Allow the additional assests to be added and wait for the compilation to be completed. This setup will create a base weather application for us to run and test with Swagger.
You can now run your application with Ctrl+F5. You may receive a certificate error when running your web api - if so you will need to trust the dev certificate from visual studio code. You will be able to launch a browser window and browse to the following url: https://localhost:5001/swagger/index.html.
In your browser you should now see a basic webpage that shows a Swagger definition of your Web Api that you just created. There should be a single GET function that you can execute and try out. Hit the Try it out button followed by the Execute button to see your Web Api in action! A list of 5 randomized temperatures should return back with a summary that has absolutely nothing to do with the actual temperature.
Congratulations - now we can get onto more complicated things in future practice sessions.