Friday, January 22, 2021

Set up a Kubernetes Cluster using Kubeadm


Goal: Setup a 3-Nodes Cluster with 1 master and 2 worker nodes



Pre-requisites:

  • A Minimum of 2 GM of RAM available to all VMs

  • A minimum of 2 CPUs are recommended 

  • Network connectivity between VMs

  • Ubuntu 16+


* You can still create the cluster even if you don’t meet the above CPU and memory recommendation, you have to force the Kube cluster to force ignore the pre-requisites check.


Steps (Use root account):

  1. Provision the VMs by using any solution like Vagrant, AWS, or Azure.

  2. Install br_netfilter on each VM if it’s not installed already.

*Run on all the nodes in the cluster

To check:

lsmod | grep br_netfilter

To Install: 

sudo modprobe br_netfilter

Run the following command

    cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf

br_netfilter

EOF


cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

EOF

sudo sysctl --system


  1. Installing container runtime (Docker) on all the nodes/VMs.

*Run on all the nodes in the cluster


Docker Installation:

## Set up the docker repository:

sudo apt-get update && sudo apt-get install -y \

apt-transport-https ca-certificates curl 

software-properties-common gnupg2


# Add Docker's official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key --keyring /etc/apt/trusted.gpg.d/docker.gpg add -



# Add the Docker apt repository:

sudo add-apt-repository \

  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \

  $(lsb_release -cs) \

  stable"


Install Docker CE

sudo apt-get update && sudo apt-get install -y \

  containerd.io=1.2.13-2 \

  docker-ce=5:19.03.11~3-0~ubuntu-$(lsb_release -cs) \

  docker-ce-cli=5:19.03.11~3-0~ubuntu-$(lsb_release -cs)


## Create /etc/docker

sudo mkdir /etc/docker


# Set up the Docker daemon

cat <<EOF | sudo tee /etc/docker/daemon.json

{

  "exec-opts": ["native.cgroupdriver=systemd"],

  "log-driver": "json-file",

  "log-opts": {

    "max-size": "100m"

  },

  "storage-driver": "overlay2"

}

EOF


# Create /etc/systemd/system/docker.service.d

sudo mkdir -p /etc/systemd/system/docker.service.d


# Restart Docker

sudo systemctl daemon-reload

sudo systemctl restart docker


# Enable docker to start at boot

sudo systemctl enable docker



  1. Install Kubeadm, Kubectl and Kubelet

*Run on all the nodes in the cluster

sudo apt-get update && sudo apt-get install -y apt-transport-https curl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list

deb https://apt.kubernetes.io/ kubernetes-xenial main

EOF

sudo apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl


  1. Initialize the Master Control-Plane on the Master node

*Run on the master node only


kubeadm init --pod-network-cidr 10.244.0.0/16 --apiserver-advertise-address=<ipaddressOfmasternode>


Add the following option if you don’t meet the memory & CPU requirement, it will force ignore the check.


--ignore-preflight-errors=all


You can give any cider range for the pod network, just make sure it’s not the same cider ranges as your VMs.


Make a record of the kubeadm join command that kubeadm init outputs. You need this command to join nodes to your cluster



  1. To start using your cluster, you need to run the following as a regular user:


mkdir -p $HOME/.kube

  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  sudo chown $(id -u):$(id -g) $HOME/.kube/config


  1. Install the Pod Network Add-on so that nodes can communicate with each other in the Kubernetes cluster. We are using the Weavenet network add-on here.


kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"


  1. Run the following Command on Work Nodes only to join the Kube Master node.


Run the Kubeadm Join command that you got from Kubeadm Init command output in the

step 5.


Example only:

kubeadm join 10.0.0.11:6443 --token lkjxey.hl6v0iuhtq76s3py     --discovery-token-ca-cert-hash sha256:eedaaa9b1e1094ef29ba9c41a0db1be3a5baa27d49ac43d467dcab4583627ff3


Add the following option if your join command is failing due to not meeting the memory & CPU etc. requirement, it will force ignore the check.


--ignore-preflight-errors=all


  1. Run the following command to test if all nodes are ready in your cluster.


kubectl get nodes -o wide


  1. If you see all node status as Ready, your Kubernetes cluster is ready to be used.


Pat on your back!


Wednesday, October 3, 2012

TFS WebAccess Error: [HttpException (0x80004005): Unable to validate data

We were getting the following error while setting our TFS2010 Web access. Sharing the solution which worked for us, might be useful for you.

Error:
[HttpException (0x80004005): Unable to validate data


Solution:
1. On App Tier server, goto C:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\Web Access\Web.
    (Please make a copy of Web.config, just in case you need the original file later.)

2. Edit the Web.config file in notepad.
3. Search "machineKey" in Web.config file.
4. Replace the <machineKey> section with following.
<machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="3DES" decryption="3DES"/>
5. Save the Web.config file.
6. Restart the Microsoft Internet Information Services (IIS) service.

TFS Web Access Error: Microsoft.TeamFoundation.WebAccess.Common.dll was invalid

I was getting this error when setting up TFS 2010 web access. I searched a lot but didn't find any solution, finally after lot of R&D I was able to fix this issue.
I may be useful for others who face this error:

Error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: The given assembly name or codebase, 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.TeamFoundation.WebAccess.Common\10.0.0.0__b03f5f7f11d50a3a\Microsoft.TeamFoundation.WebAccess.Common.dll', was invalid.

Solution:
We get the following error due to IIS_IUSRS a/c is missing some group policies.
"'C:\Windows\assembly\GAC_MSIL\Microsoft.TeamFoundation.WebAccess.Common\10.0.0.0__b03f5f7f11d50a3a\ Microsoft.TeamFoundation.WebAccess.Common.dll'
Here is what we need to do:
On App Tier->Start-Run- gpedit.msc -> Computer Configuration->Windows Setting->Security Setting->Local Policy->User Rights Assignment
Add the IIS_IUSRS a/c to the following policies:
    • Bypass Travers Checking
    • Impersonate a client after authentication
    • Log on as batch job
We were faced this issue two times in our differrent environment. And the above solution fixed it for both. So it's worth a try.

Thursday, October 13, 2011

How to get changeset information using TFS API?

_________________________________________________________________________________

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;

public void GetChangesetsInfo()
        {
            TfsTeamProjectCollection proj_coll = new TfsTeamProjectCollection(new Uri("http://NvnTfsserver:8080/tfs/defaultcollection/"), new System.Net.NetworkCredential(username, password));
            proj_coll.EnsureAuthenticated();

            VersionControlServer vcs = (VersionControlServer)proj_coll.GetService(typeof(VersionControlServer));

            //Following will get all changesets since 20 days. Note : "DateVersionSpec(DateTime.Now - TimeSpan.FromDays(20))"
            System.Collections.IEnumerable history = vcs.QueryHistory("$/Stakeholders Test Project", LatestVersionSpec.Instance, 0, RecursionType.Full, null, new DateVersionSpec(DateTime.Now - TimeSpan.FromDays(20)), LatestVersionSpec.Instance, Int32.MaxValue, false, false);

            foreach (Changeset changeset in history)
            {
                Console.WriteLine("Changeset Id: " + changeset.ChangesetId);
                Console.WriteLine("Owner: " + changeset.Owner);
                Console.WriteLine("Date: " + changeset.CreationDate.ToString());
                Console.WriteLine("Comment: " + changeset.Comment);
                Console.WriteLine("-------------------------------------");
            }
        }

 

Wednesday, October 12, 2011

How to get TFS Project groups and members information using TFS2010 APIs ?

-------------------------------------------------------------------------

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;

 
public void PrintTFSGroupMembersInfo()
        {
            TfsTeamProjectCollection proj_coll = new TfsTeamProjectCollection(new Uri("http://NvnTFSServer:8080/tfs/defaultcollection/"), new System.Net.NetworkCredential(username, pass));
            proj_coll.Authenticate();

            VersionControlServer vcs = (VersionControlServer)proj_coll.GetService(typeof(VersionControlServer));
            TeamProject[] TPs = vcs.GetAllTeamProjects(false);

            IGroupSecurityService sec_groups = (IGroupSecurityService)proj_coll.GetService(typeof(IGroupSecurityService));


            foreach (TeamProject TP in TPs)
            {
                Console.WriteLine("Team Project : " + TP.Name);
                Console.WriteLine("Group Members : ");

                Identity[] app_groups = sec_groups.ListApplicationGroups(TP.ArtifactUri.ToString());

                foreach (Identity app_grp in app_groups)
                {
                    Identity grp = sec_groups.ReadIdentity(SearchFactor.Sid, app_grp.Sid, QueryMembership.Direct);

                    foreach (string members in grp.Members)
                    {
                        Identity member = sec_groups.ReadIdentity(SearchFactor.Sid, members, QueryMembership.Direct);

                        Console.WriteLine("     " + member.DisplayName);
                        foreach (string mm in member.Members)
                        {
                            Identity m = sec_groups.ReadIdentity(SearchFactor.Sid, mm, QueryMembership.Direct);

                            Console.WriteLine("         " + m.DisplayName);
                        }
                    }
                }


            }
        }

Friday, September 9, 2011

TFS 2010 Training Kit Released

This is for all who are interested in learning TFS 2010. Microsoft has recently released the TFS 2010 Training Kit. You can download the TFS 2010 Training Kit by clicking on the link given below.  The training kit is very well designed, authored by Yuval Mazor and Asaf Stone. This training kit is really useful for all developers, testers, managers and all other in team.

This Training Kit contains several demos and hands-on labs that require some additional setup. For instructions, please see the Setup document.

Friday, August 19, 2011

How to get members list for a Team Project using TFS API?

Try the following code. Rember I have written it for TFS08, so there may be some functions don't work well for TFS2010.

----------------------------------------------------------------------------------------------------------
public void printMemberList(string teamProject)
        {
           
          
                          
            TeamFoundationServer tfsServer = new TeamFoundationServer("TFS_Server_name");
            IGroupSecurityService sec = (IGroupSecurityService)tfsServer.GetService(typeof(IGroupSecurityService));

            VersionControlServer versionControl = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));

            TeamProject tp = versionControl.GetTeamProject(teamProject);

            Identity[] appGroups = sec.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri);

            foreach (Identity group in appGroups)
            {

                Identity[] groupMembers = sec.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);

                foreach (Identity member in groupMembers)
                {

       

                    if (member.Members != null)
                    {
                        foreach (string memberSid in member.Members)
                        {
                     
                            Identity memberInfo = sec.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);

                           
                            Console.WriteLine(member.DisplayName + "----" + memberInfo.DisplayName.ToString());
                          
                           
                            
                        }

                    }

                }

            }

        }

Version Control System - 10 Best Practices for Developers


“I have been working in Software Configuration Management area for almost last 5 years.  I have administrated some of the efficient Version Control Systems like “VSS, Dimensions, and TFS.” As a part my daily experience in this area, I have learned some best practices we should follow for a quality software development.
I have documented these best practices and sharing with you all. I hope you get something good out of it.”

Version Control Systems:  A Version Control System secures your artifacts, tracks the changes to the artifacts and provides you many features for a quality deliverable.  The Version Control System enables everyone in the team to work more efficiently in a collaborative way.
Version Control System is a common requirement in all modern software development projects. It not only provides a mechanism for checking in and out the source code from central repository but also it keeps track of which changes were made, who made those changes, when & why they were made. Modern Version Control Systems provide many more additional features like efficient branching & merging methods, builds features, testing & deployment features etc.
In order to be successful using a source code repository as part of the software development process, the development team must agree that they always refer Version Control Systems for using the artifacts. All developers must be in the habit of following all good practices when using a version control system.
Please refer the following best practices I have documented below:

Following are the best practices all developers should follow.
1.)  All developers must use Version Control as their source code repository.
All development teams must have an efficient Version Control System for securing their work. And the first step should be to add the source code to Version Control systems at the earliest. No member should be allowed to work offline of Version Control systems. All members should reference the code for Version Controls systems and make sure that the project is online.

2.)  Developers should not circumvent Version Control.
In order to modify any files, developers must check the files out from Version Control.
I have seen in practice that many developers avoid/skip using Version Control System for checking-out/checking-in the code. Many developers checkout the file but they don’t checkin the changes on regular basis, which is very bad approach. Consider an example, you checked out a file three days back and made lot of changes but you didn’t check the changes in and now unfortunately your machine gets crashed. What you will do? So get into the habit of always using Version Control for checking out the files and do the regular check-ins.

3.)  Developers should not change the attributes of files on their file system.
Developers should avoid changing attributes of files on their file systems because when they will check-in the changes, these changes will also be saved in Version Control. Changed attributes may behave differently for other developers, when they will use these files.

4.)  All code / executable should originate from Version Control and should be applied to development, test and production systems using automated methods.  Developers should not modify any of these systems manually.

5.)  Avoid checking-in the unsuccessful code.
Developers should not check in code that cannot be successfully compiled.  Doing so would break the scheduled build process and delay the development cycle. This can create problem for other Team, working parallel on the project. The best practice is always do a local build/compile your application before checking in and if the application builds successfully, then only check-in the changes to code repository.

6.)  Perform regular local & server builds.
Build is process of validating, compiling, testing & integrating your code as a complete solution. A build process makes sure your code is well integrated and working what you are aiming for.  Builds must be done on a regular basis. It’s always a good idea to have a dedicated team for build and successful build should be a top priority for them.
Make sure you regularly perform server builds additional to local builds. Server builds make sure that your application doesn’t have any local machine specific dependencies on code.
Implement efficient build plans for your application which should include Continuous Integration Builds, Scheduled Build and Ad-hoc builds.
Use efficient build tools. Many of the advanced build tools automatically fire a server build whenever you commit the changes to code called CI builds. It helps you in identifying early warning of broken/incompatible code.

7.)  Create a separate common folder for Dependencies.
If we are using any Third Party DLLs/Components, then we should have a common folder in Version Control (Ex. Dependencies or Library) and refer the components from there. I have seen many developers add shared components to all the projects and create different copies of same components, which is not at all a good practice. Instead, we can have a common folder for Shared/Third Party components and refer them.

8.)  Avoid storing Binaries in Version Control.
It’s a good practice to avoid adding binaries (like code generated files like .dlls, .pdb etc.) to Version Control, these eats a lot of space. Also these are not a source code, these are just generated binaries by our code, which we can do anytime, we just need to build our source once and we will have these.  So only add binaries, if it’s really needed for your project.
9.)  Don’t create unnecessary branches.
Before creating branches, pay attention – every branch you create does have a cost so make sure you get some value from it. More the branches you will have, more time/cost you will need to spend on Merge conflicts and additional testing. So only create the branches necessary for your development efforts.

10.)  Avoid changings source in Main line.
While creating directory structure in Version Control systems, make sure you have one main line/base line folder which stores your main code. You must avoid direct changes in this code. This main branch should be a stable snapshot of the product and it’s the latest working copy which can be shared with Customers, QA or external teams.
Always create needed branches, make the code changes are done in those branches and after the successful build merge the changes using proper Reverse & Forward Integration with Main line. In this way, we will make sure Main will always have a good/working code.