How to use Azure Kubernetes Services

About the author:

Tiago Rosendo Developer at Braspag and Cielo, backend from the heart and in love with frontend, JS and Docker enthusiast, and on the free time does not dispense Online gaming.
  LinkedIn: / E-mail:


Let’s talk about Azure Kubernetes Services, commonly known as AKS. We use it to perform deploys in our main applications, from the most basic to the most complex, all with high availability!

Running Docker containers on a local computer is very simple, only a command docker run nginx and done, You have your beautiful container running, however, when you have the need to run the same container on a cloud environment, the scenario changes… You have to build your cluster, configure the auto-scale, configure the load balance… OH MY GOD, HOW MANY THINGS! A certain day I took some time to search for a solution that spared my time, therefore, I thought to myself::

“It can’t be possible that no one has ever made something to simplify this repetitive process”

One of the solutions found was the Azure Kubernetes Services, it allows building a Kubernetes cluster with a single command, so there is plenty of time to focus on your application and not on the machines configuration.

But what is Kubernetes? In short, Kubernetes is an orchestration tool for containers, you build your container with Docker and Kubernetes does all the deploy, auto scale, service discovery and much more. In case you want to know more about Kubernetes, the link of their documentation follows:

Mounting a cluster in Kubernetes

I’m considering that you already have the Azure CLI configured in your machine. In case you don’t, the configuration tutorial link follows:

To mount a cluster using AKS, a single command is needed:

"az aks create -n NomeDoSeuCluster -g NomeDoGrupoDeRecursos --generate-ssh-keys"

Replace NomeDoSeuCluster for the name of your cluster.

Replace NomeDoGrupoDeRecursos for the name of the features group where your cluster will be provisioned. The feature group has to exist in your Azure account.

After a couple of minutes, you`ll have your cluster mounted, as can be seen on the image below:

After mounting our cluster, we`ll get the access credentials with the command:

"az aks get-credentials -n NomeDoSeuCluster -g NomeDoGrupoDeRecursos"

In case everything works, you’ll get the following message:

Now let’s configure the Kubectl Cli, it will be used to communicate directly with Kubernetes, to do so, just execute the following command:

"az aks install-cli"

If all went well, the following message will be displayed:

Now let’s check what is the machine state of our cluster. For that, we’ll use the command:

"kubectl get nodes"

Finally we are going to run our first application inside our cluster!!! For that, we’re going to use the command run:

"kubectl run meu-nginx --image=nginx --replicas=1 --port=80"

We’ll call the get pods to check if our application was successfully deployed:

As we have seen on the image above, our application was “deployed”, however it isn’t available on the internet yet. To make our application available, we’ll use the command expose:

"kubectl expose deployment meu-nginx --port=80 --type=LoadBalancer"

Now just call the command get services para descobrir qual o IP que nossa aplicação recebeu, essa etapa pode demorar alguns minutos:

"kubectl get services --watch"

As we can see, our application received the IP: Lastly, we’ll access our application IP to see if all worked fine!

And it works, doesn’t it? 😊


That’s all for today, guys. I hope you have enjoyed. This was a little demonstration of how the AKS/Kubernetes can help us on the orchestration of our containers. I intend to write a part 2 of this article explaining how to use the Azure Container Instance along with Kubernetes, I’ll leave some interesting links below for those who want to go dwelve on the subject:


e-Commerce Good Practices

Whether out of curiosity or out of necessity, you’ve probably wondered about how the number of a credit card is defined. Some people get to think that those are random numbers, or sequential, given by the card brands or emitting banks, but the truth is that the card number follows a specified standard and it is possible to know the card brand, card type and holder’s account, only by observing the card number; in some cases, in fact, it is possible to know the country of origin, just by seeing its number.

In order to contribute to the reduction of transactions declined by the code 14 – invalid cards, Cielo recommends the use of the Luhn algorithm for credit and debit cards number sequence verification on your store. From this measure, the retailer will be able to avoid that a transaction with the card entered wrongly is send to processing.

For that, Cielo recommends that, at the moment that the holder enters the card number and the Luhn algorithm detects the entering is wrong, the retailer will have to display the information clearly, requesting that the card is entered again or to try another card.

Card number

Visa Card

Basically, the card number is made of three parts:

  1. Bin or Inn - Bank identification number, or Issuer identification number, is the number that identifies the emitting bank of the card brands Visa, Mastercard, Amex, among others, through the first card digits. In the case of the example above, the Bin is 4, being the Visa identifier.
  2. Client account - After the bin, the next digits identify the holder’s account number on the emitting bank. Right after the bin, the next 14 digits are the client account identifier: 012 0010 3714 111.
  3. Verification digit - This last digit is used to verify if the credit card number is valid. To get to the verifying number, an algorithm called Luhn is used. In the case of the example card above, the verifying digit is 2.

Card information

After validating that the card is valid through the verifying digit obtained through Luhn algorithm, we can verify if the card number is correct according to the chosen card brand. Cielo does not recommend that a validation is made through BIN – first card digits; this recommendation is important because there can be a collision of the same BIN number for different card brands. Some brands have 13, 15 or 16 digits and CVV has 3 or 4 digits. The table below presents the digits quantities in each brand and their respective CVV. Use this information along with Luhn algorithm for a complete client card number validation..

Card brand Number of digits CVV digits
Visa 13 or 16 digits 3 digits
Mastercard 16 digits 3 digits
Amex 15 digits 4 digits
Diners Club International 14 digits 3 digits
JCB 16 digits 3 digits
ELO 16 digits 3 digits

Validation of card numbers

Validation of card numbers

The validation of card numbers of most card brands worldwide are made through an algorithm called Luhn, also knows as module 10. Let’s suppose that the client has informed the following credit card number: 4012001037141112.

First step is to remove temporarily the last digit. In this case, the digit 2. The new number will be like this: 401200103714111.

Position 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Card number 4 0 1 2 0 0 1 0 3 7 1 4 1 1 1 x

The second step is to multiply, beginning from the first digit, all digits that are in pair position by 2 and all digits in odd positions by 1:

Position 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Card number 4 0 1 2 0 0 1 0 3 7 1 4 1 1 1 -
Multiplications x2 x1 x2 x1 x2 x1 x2 x1 x2 x1 x2 x1 x2 x1 x2  
Results 8 0 2 2 0 0 2 0 6 7 2 4 2 1 2  

The third step is to get the multiplications result and add up all digits:

Digits Calculation Result
802200206724212 8+0+2+2+0+0+2+0+6+7+2+4+2+1+2 38

The fourth step is to get the rest of the euclidean division from the third step result by 10: 38 / 10 = 3, with rest 8. The fifth step is to subtract the rest of 10: 10 – 8 = 2..

Calculation IV Quotient Rest Calculation V Result
38/10 3 8 10-8 2

The number two is the verification number; if the subtraction result on the fourth step is 10, the verification digit will be 0. To verify if the card number informed by the client is valid, only verify the number of the first step + the verification digit is equal to the card number informed by the client..

Another example of calculation, this time with a Mastercard.:

Card 5 4 5 3 0 1 0 0 0 0 0 6 6 1 6 7 Result
Step 1 5 4 5 3 0 1 0 0 0 0 0 6 6 1 6    
Step 2 10 4 10 3 0 1 0 0 0 0 0 6 12 1 12    
Step 3 1+0 4 1+0 3 0 1 0 0 0 0 0 6 1+2 1 1+2   23
Step 4                               23%10 3
Step 5                               10-3 7

Validation on the backend

However, even though we have the verifier plugin on frontend, it is fundamental, for safety considerations, that a validation in fact occurs on the backend. For that, the function below will help you doing the validation:

function cardIsValid($cardNumber)
    $number = substr($cardNumber, 0, -1);
    $doubles = [];

    for ($i = 0, $t = strlen($number); $i < $t; ++$i) {
        $doubles[] = substr($number, $i, 1) * ($i % 2 == 0? 2: 1);

    $sum = 0;

    foreach ($doubles as $double) {
        for ($i = 0, $t = strlen($double); $i < $t; ++$i) {
            $sum += (int) substr($double, $i, 1);

    return substr($cardNumber, -1, 1) == (10-$sum%10)%10;

To use it, you just have to test the card number sent by the client:

if (cardIsValid($customerCardNumber)) {
  // o cartão é válido e podemos dar andamento na integração