Configuring Kubernetes Cluster on AWS and running/scaling a .Net Core application

Development Environment Setup

Containerize the application

  • Clone this repo to a folder
  • Open a command prompt and navigate to your project folder.
  • Use the following commands to build and run your Docker image:
  • View the .Net Core application running from a container by navigating to localhost:8000

alt text

Push the image to DockerHub

  • Log in on https://hub.docker.com/

  • Click on Create Repository.

  • Choose a name (e.g. kubeservice) and a description for your repository and click Create.

  • Log into the Docker Hub from the command line

just with your own user name and email that you used for the account. Enter your password when prompted. If everything worked you will get a message similar to

  • Check the image ID using

and what you will see will be similar to

  • Tag image
  • Push image to the repository created in previous steps

Configure Kubernetes Cluster on AWS

  • Login to your AWS console

  • Generate access keys for your user by navigating to Users/Security credentials page

  • Make sure your IAM user has following permissions:

  • Make sure to configure the AWS CLI to use your access key ID and secret access key
  • Create an S3 bucket for kops to use to store the state of the Kubernetes cluster and its configuration
  • Enable versioning to revert or recover a previous state store.
  • Set the Kubernetes cluster name and S3 bucket URL environment variables
  • Generate Kubernetes cluster configuration using kops
  • Finally, build the Kubernetes cluster on AWS using following kops command. This might take a few minutes to boot the EC2 instances and download the Kubernetes components.

alt text

  • Validate the cluster to ensure the master + 2 nodes have launched

  • Finally, you can see your Kubernetes nodes with kubectl

Deploy the Kubernetes Dashboard

  • Deploy the Kubernetes Dashboard by running following command
  • Access Dashboard using the kubectl command-line tool by running the following command
  • Execute the below command to find the admin service account token
  • Provide the above service account token on the service token request page alt text

alt text

alt text

Deploy the Application in Kubernetes using .yml file

  • Below is the content of kubeservice-deploy.yml file
  • Click on + CREATE on top right corner of the Kubernetes Dashboad
  • Navigate to ‘CREATE FROM FILE’ tab and select the kubeservice-deploy.yml file

alt text

  • Finally, click on UPLOAD button. This will deploy the application and dashboard looks like below once the deployment is completed.

alt text

alt text

  • Access the application using external endpoint listed in Kubernetes – Services Dashboard

alt text

alt text

Scaling Kubernetes Cluster pods

  • Verify the current replicas # and deployment of application alt text

  • Navigate to Deployments and click on Scale as shown in below screen alt text

  • Change the Desired number of pods to 5 instead of 3 alt text

  • Click OK to scale the pods to 5 alt text

  • Finally, dashboard looks like this once the deployment is completed alt text

Delete the Kubernetes Cluster

  • Finally, when you are ready to tear down your Kubernetes cluster, you can delete the cluster using following command

Share the Post: