Docker

Docker is written in the Go programming language.

The Docker daemon

The Docker daemon ( dockerd cli ) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes.

A docker daemon can also communicate with other docker daemons to manage Docker services.

The Docker client

The Docker client ( docker cli ) is the primary way to interact with Docker.

When you use commands such as docker run, docker build, docker pull , the Docker client sends these commands to dockerd .

The docker command uses the Docker API.

The Docker client ( docker cli ) can communicate with more than one Docker daemon.

Continue reading

Linux Terminal Check stdin, stdout and stderr

When we want to check whether current terminal is attached to stdin, stdout and stderr streams or not, we can use the below codes. I tried with piping, and redirection so both works well.

As seen in below 6 usages, stdin is not listed in output of commands except first one. Because stdin is used by piping or redirection.

$  ([ -t 0 ] && echo stdin; [ -t 1 ] && echo stdout; [ -t 2 ] && echo stderr; echo hello)

stdin
stdout
stderr
hello
$ echo hello | ([ -t 0 ] && echo stdin; [ -t 1 ] && echo stdout; [ -t 2 ] && echo stderr; cat)

stdout
stderr
hello
$ ([ -t 0 ] && echo stdin; [ -t 1 ] && echo stdout; [ -t 2 ] && echo stderr; cat) <<<"hello"

stdout
stderr
hello
Continue reading

Azure DevOps: CI/CD IaC with YAML Pipeline

Sign in to your organisation (https://dev.azure.com/{yourorganization})

Azure DevOps looks like the following screenshot.

Find more details about key consepts in Azure Pipelines Key Concepts

Find more details about extending Azure Pipelines Templates in Azure Pipelines Templates

Find more details about Azure template parameters in Azure Pipeline Template Parameters

Find more details about Azure template predefined variables in Azure Pipeline Template Predefined Variables

Find more details about Azure template script variables in Azure Pipeline Template Script Variables

Find more details about usage of expressions in Azure Pipelines Expressions

In a pipeline, template expression variables (${{ variables.var }}) get processed at compile time, before runtime starts. Macro syntax variables ($(var)) get processed during runtime before a task runs. Runtime expressions ($[variables.var]) also get processed during runtime but are intended to be used with conditionsand expressions

Find more details about usage of Azure template variables in Azure Pipeline Template Variable Usage

Azure DevOps Organizations Page

Continue reading

Azure DevOps REST API

When we need to create, retrieve, update or delete access to the Azure DevOps services's resources, we can use Azure DevOps REST API.

Find more Azure DevOps REST services in https://docs.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-7.1

Process REST API

Get Process Id in your organization

Find more details in https://docs.microsoft.com/en-us/rest/api/azure/devops/core/processes/list?view=azure-devops-rest-7.1

ORGANIZATION=$1

PROCESS_NAME=$2

PAT=$3

curl --silent --user :$PAT \
--request GET "https://dev.azure.com/$ORGANIZATION/_apis/process/processes?api-version=6.0" | jq -r '.value[] | select(.name=="'$PROCESS_NAME'") | .id'
$ . ./getProcessId.sh kenanhancer Agile blablabla

adcc42ab-9882-485e-a3ed-7678f01f66bc

Get Process in your organization

Find more details in https://docs.microsoft.com/en-us/rest/api/azure/devops/core/processes/get?view=azure-devops-rest-7.1

echo -n "Organization: " && read ORGANIZATION

echo -n "Process Name: " && read PROCESS_NAME

echo -n "PAT: " && read PAT

PROCESS_ID=$(. ./getProcessId.sh $ORGANIZATION $PROCESS_NAME $PAT)

curl --silent --user :$PAT \
--request GET "https://dev.azure.com/$ORGANIZATION/_apis/process/processes/$PROCESS_ID?api-version=6.0" | jq -r .
$ . ./getProcess.sh
Organization: kenanhancer
Process Name: Agile
PAT: blablabla

{
  "id": "adcc42ab-9882-485e-a3ed-7678f01f66bc",
  "description": "This template is flexible and will work great for most teams using Agile planning methods, including those practicing Scrum.",
  "isDefault": true,
  "_links": {
    "self": {
      "href": "https://dev.azure.com/kenanhancer/_apis/process/processes/adcc42ab-9882-485e-a3ed-7678f01f66bc"
    }
  },
  "type": "system",
  "url": "https://dev.azure.com/kenanhancer/_apis/process/processes/adcc42ab-9882-485e-a3ed-7678f01f66bc",
  "name": "Agile"
}
Continue reading

Azure DevOps: Creating Personal Access Token (PAT)

Sign in to your organisation (https://dev.azure.com/{yourorganization})

Treat and use a PAT like your password and keep it a secret.

Use your PAT anywhere your user credentials are required for authentication in Azure DevOps.

You can use a personal access token (PAT) as an alternate password to authenticate into Azure DevOps.

A personal access token contains your security credentials for Azure DevOps. A PAT identifies you, your accessible organizations, and scopes of access. As such, they're as critical as passwords, so you should treat them the same way.

If you're working within Microsoft tools, then your Microsoft account (MSA) or Azure Active Directory (Azure AD) is an acceptable and well-supported approach. But, if you're working with third-party tools that don't support Microsoft or Azure AD accounts – or you don't want to provide your primary credentials to the tool – use PATs to limit your risk.

find more details about creating PAT in Azure DevOps

Continue reading

How to install Ansible with brew or pip

You can install Ansible quickly in your system with Homebrew( or PIP(Package manager for Python)

Install Ansible with Homebrew

If you are using macOS, then you can use Homebrew.

First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit previous post below.

Run the following commands in your terminal without $ sign.

$ brew update
$ brew install ansible

Checking Ansible version

$ ansible --version

ansible 2.9.7
  config file = None
  configured module search path = ['/Users/kenanhancer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/kenanhancer/.pyenv/versions/3.8.2/lib/python3.8/site-packages/ansible
  executable location = /Users/kenanhancer/.pyenv/versions/3.8.2/bin/ansible
  python version = 3.8.2 (default, May  6 2020, 12:47:50) [Clang 11.0.3 (clang-1103.0.32.59)]

Install Ansible with PIP

Ensure that you have Python and PIP in your system. Check the following page about Python installation.

$ pip install ansible
$ ansible --version

Updating Ansible

$ pip install --upgrade ansible

Installing specific Ansible version

$ pip install ansible==2.2.2.0
$ pip install ansible==2.0.1.0

Kubernetes configure kubectl to use multiple clusters

First of all, you need to have kubectl CLI in your host machine. So, follow the below steps.

Install with Chocolatey on Windows

choco install kubernetes-cli

Install with Homebrew on MacOS

brew install kubernetes-cli

Install with Kubernetes Official Documentation(with Curl)

Follow this link https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-macos

Test to ensure the version you installed

kubectl version

Checking kubectl config

When you run below command, you will see output as shown in the following screenshot. I didn't configure yet so, it shows an empty config.

kubectl config view
Continue reading

Creating, Starting, Stopping, Packaging and Publishing a Vagrant Box

I use Vagrant for local development in order to build any development environment. For example, when I need a Kubernetes multi node cluster, I can demonstrate with Vagrant quickly(https://kenanhancer.com/2019/09/08/kubernetes-multi-node-cluster-with-one-updated-vagrant-file/). After I complete my exercise about any technology, I also publish to Vagrant Cloud so that it can be used later without wasting time. But, I am not using only Vagrant, there are different technologies and there are different CLI for them. So, if I don't use one technology sometime, I can forget some important commands. That's why, this post is important for me to remember Vagrant CLI 🙂

To read more information about Vagrant CLI https://www.vagrantup.com/docs/cli/ follow official link.

Continue reading

Kubernetes multi node cluster with One Updated Vagrant File

Actually there is already a Kubernetes multi node cluster post (https://kenanhancer.com/2018/09/26/kubernetes-multi-node-cluster-with-vagrant/) in this blog. But, this one is different. That post was showing 3 empty virtual server up and run later install tools step by step so it was taking too much time. If you run this Vagrantfile, it will create one master node and 2 worker nodes in Virtualbox. This Vagrantfile is also more configurable. If you need more servers, just append new item in "servers" array in Vagrantfile.

This is the expected result 🙂 As I mentioned at the beginning of the post, one master node and two worker nodes are created in Virtualbox.

Kubernetes single node cluster with Minikube and Vagrant

The following Vagrantfile code(syntax is Ruby) is creating single node Kubernetes cluster with Minikube.

Copy above code and follow the following screenshots. Run the following commands in Terminal.

mkdir MinikubeVagrant

cd MinikubeVagrant

nano Vagrantfile

Paste the Vagrantfile content like below.

save Vagrantfile and run the following command to start virtual machine.

vagrant up

Creating Kubernetes Dashboard Proxy

After Vagrant is up, it means that Minikube is ready to use. So, connect with SSH to Vagrant machine and run the following code to start Kubernetes Dashboard Proxy.

kubectl proxy --address 0.0.0.0 --port=8001 --accept-hosts '.*'

Connecting to Kubernetes Dashboard from Host machine

Click one of the following link to connect the Dashboard. Ta taaa 🙂

http://127.0.0.1:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login

or

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login

Rest of the details are already mentioned in this blog link Kubernetes multi node cluster with Vagrant (included Kubernetes Dashboards, Grafana, Prometheus)

read the Kubernetes Dashboard Access Control paragraph.