miércoles, 3 de octubre de 2018

Using Docker and SQL Server


 In the last few years we've seen that web services are amoung us. Now microservices are the key Essence of these platforms. microservices to efficience the resources and as a response of that containers which are the microservices for the operative system at horizontal scale for vm machines cheaper and faster in which  dbms now live in.

In this scenario it is easier to mantain and develop, to manage the phylosophy to have Elastic Scalability attribute is to destroy if it is not in use as the resources represent money efficience due the velocity of it's creation.
All this is not new concepts, they've been around for some time since IaaS were designed.
So then what is a Microservice and how did it operate?

What is a Microservice?

It is a service oriented architecture (SOA) based in which a service component it is desinged to work independent one from another, but they cooperate between each other to desing a complex system. This SOA applied infrastructure is used or contained in the IaaS paradigm theorically.  The practical idea is often to provide a API endpoint in order for Dev Ops can connect  or consume the services they are familarized to  infrastructure, in this way makes it easy to adapt and adjust.

what is important to keep in mind when examining Microservice for a layout infrastructure descision, is that even that this is the new paradigm for the infrastructure design is important to understand the applicacion services  because you can conciently decide that monolithic architecture is best fit for your design for your particular needs. 

Monolithic vs Microservice paradigm Architecture

Monolithic =1 Microservices >=1 service(s) or in our case containers or pods.
with this basic thought the design orientation.

The following link is the Microsoft design layout for the Azure infrastructure

what is interesting from Microsoft note is they show the attributes that a microservice should be: " small, independant and loosely coupled."  they are low persistant in time as described above, this technology is oriented to re-create services very fast. and this apply for databases and all services. 

This is an example on how Microsoft describes their layout:


If you want to understand more about how to adapt with a new design pattern, this reading may interest you:

Chris Richardson has dedicated a post for showing some differences and how can you adapt into real life scenarios.

What are Kubernets? and 
What is Docker?
The Adoption of contaniers come from the FreeBSD project. and Improved by Docker and started adopting in 2013. All these open source technology has been sustained and improved by the Cloud Native Computing Foundation.  https://www.cncf.io/

Kubernetes infrastructure is open source for managing containers in different hosts providing infrastructure to build mantain and scale the microservice containers, and what you need to have is a YAML or JSON which describes your service. Also you can create Pods which basically are units or nodes for the worloads that you run on Kubernetes. 
 (you can create one or more pods). 

They way you can setup or deploy Kubernets are:

1) Local Machine

2) Hosted (with the the partners of the solution) Stackpoint, Openshift , IBM.

3) Turnkey - Cloud  ( Azure, IBM , Stackpoint, IBM...)

4) On Premise

The recommended scenario is miniKube which is practical web-based environments easy to access but are not perssistant. if you are more advance Linux user use kubectl, which is the daemon for Kubernetes.

So what is Docker then? Docker is an adaptation of the same opensource infrastructure I have been mentioning but it provides us with a platform in which we can easily administrate our containers. They have focused on providing services to quickly adapt and use.
It is a mixture between a IaaS and PaaS, because they provide both, mading easy to manage for DevOps and forget about configuration. however since they all are the same open source technology you can go into more sophisticated using docker.

Basic Design Docker Structure

Docker CE consist of a web based platform and client desk tools that connects to platform that interfaces with the platform. 

Kitematic - which is the previous version of platform for Windows 7 versions, this app allows you to control from dashboard and see your images and containers.

Docker CLI  based where it communicates between Docker VM and Docker HUB. The communication between messages on Local Docker VM and Docker HUB CLI utilize JSON responses all these infrastructure is what provides Docker in order to facilitate 
its use. with it, makes the communication between teers. for the end user you can use the dashboard without knowing or being easy to use. As explained above you can also use CLI commands, YML and JSON language for all this technology.

Bellow image shows the actual configuration JSON response for a particular container.

which in comparision seemly would correspond to YML structure for the Pod.

Benefits on Usign Docker 

* Easy to implement on local machine.

* Practical to mantain CRUD operations.

* Benefit on Resource utilization on Idle condition (saves $$)

Basic commands on Docker

The bellow description is based on a Windows configuration for docker, and you will see that the access mode is mostly through Powershell as a CLI.

docker-machine- Trhough this command you can manage the VM OS Linux where the images and containers are applied living in this O.S. VM. (boot2docker) 

the boot2docker distro is simply a Debian adapted to docker so no worries you can do what you know with linux on this one.

here is an example of how docker stores internally the logs of the container operations if you need to inspect details.

additionally you can access to the VM directly to PS instead of using a VM Manager.

status: You can verify the ip of the docker machine created

config: You can check the certificates and ssh keys for your machine with this commands.

NOTE you can use Virtualbox to access this VM and use normal linux commands.
Insde docker machine you can execute  start - stop - status - ip - create virtual machine, once this machine is running the containers can be executed. 

docker - Through this command you can manage the contaniers services in order to execute any service that you need to deploy.
              ps -   execute this command to know the processes running under docker.
              run -  execute this command to run a specific image selected and create a container.
              start -  execute this command to start the container already created.
              stop -  execute this command to stop the container already running.
              exec - execute a binary command inside the container (you have to be aware that each container has its own)
Initiating   Docker on Windows

Running a container

Once you have previously downloaded the image you require either with Kitematic or command: docker pull mcr.microsoft.com/mssql/server:2017-latest

you execute run the image selected.

you can see the process that is running using ps

on the above image you can see highligted is the container id, this will be useful in the future in order to re-execute a container that you want to re-use say the next day.
Also you can see the status of the container created and the port where is running, I have set it default but you can desing it as you want by creating a tunnel rule port forwarding from host to target.

This is the perspective of use in docker from OS guest resources.

as you can see bellow here are the VBOX resources...

and if we inspect deeper we see the process from the boot2docker

you can also Pause or unpause the sql server configured

now that it is unpaused you can access the SQL Server:

on bellow image you can see that on internal path /opt/mssql-tools/bin you can access sql binaries 

At this point you can connect through SSMS on your local machine note on highlighted that this is the image previously set.

No hay comentarios:

Publicar un comentario