Learn

Learn about latest technology

Build

Unleash your talent and coding!

Share

Let more people use it to improve!
 
Mostrando entradas con la etiqueta kubernetes. Mostrar todas las entradas
Mostrando entradas con la etiqueta kubernetes. Mostrar todas las entradas

AWS EKS just configuring it manually

viernes, 28 de junio de 2019


This is a technical article focused in to create, manually, a proper configuration to sent commands from your local environment to AWS EKS Cluster.

In AWS-EKS you will need that your local kubectl CLI can talks with your AWS EKS Cluster. Every thing is oriented to install AWS CLI. So What happen if you don’t want to  install AWS CLI? In that case the configuration process to talk to the EKS cluster must be done manually. Let’s check what does it means.
Before that, you will need to know some technical concept about k8s and AWS. I suppose that you feel confortable or at least have basic knowledges in the following contents:
  1. AWS IAM: remember that you shouldn't use your AWS account root user.
  2. Kubectl CLI: command line interface for running commands against Kubernetes clusters that must be installed on your local environment.
Our utter configuration is composed for 2 files in our local environment:
  1. ~/.kube/config: We have a config file, usually KUBECONFIG, this file is used to configure access to clusters . It is a document like every definitions document in k8s with fields like (apiVersion, kind, etc) so the first thing that you need to know is the location of the cluster and the credentials to access it.
  2. ~/.aws/credentials: These are the credentials with which I going to create my cluster, authenticated with my IAM account.
At the same time we need something(software/tool) that with our credentials will make available the authentication to our k8s EKS cluster, this role is performed by aws-iam-authenticator.
You can find a proper installation guide of aws-iam-authenticator or  try with the following steps:
the below lines are referred to OSX but if you are working with linux then you will need to change in line 3 the bash file instead of .bash_profile should be .bashrc

1
2
3
curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/darwin/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && echo 'export PATH=$HOME/bin:$PATH' >> ~/.bash_profile

Testing your above aws-iam-authenticator installation: aws-iam-authenticator help

Now we are going to indicate the location/name of our kubconfig file and its content.


~/.kube/config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
apiVersion: v1
clusters:
- cluster:
    server: <endpoint-url>
    certificate-authority-data: <base64-encoded-ca-cert>
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: aws
  name: aws
current-context: aws
kind: Config
preferences: {}
users:
- name: aws
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: aws-iam-authenticator
      args:
        - token
        - -i
        - my_cluster_name
        # - -r
        # - arn:aws:iam::835499627031:role/eksServiceRole
      env:
        - name: AWS_PROFILE
          value: my_profile_name
yaml definition 1.0

Should be interesting have a look to several lines at yaml definition 1.0 for example

In line 20 aws-iam-authenticator [command] [Flags:] it runs the cluster authentication using AWS IAM and get tokens for Kubernetes, in order to get there, we have our credential files with our access keys/secrets that we are gonna explain below.

We indicate below the location/name of our credentials file and its content.

~/.aws/credentials

[my_user_in_IAM]
aws_access_key_id=generated_aws_access_key
aws_secret_access_key=generated_aws_secret_access_key
config definition 1.0

In config definition 1.0 I indicate the structure of the credential files but you can find more about manage access keys in IAM documentation for manage access keys. In the picture below you can find in an easy way how create keys/secrets in your AWS IAM account. The same key/secrets/user_in_IAM used to create your EKS Cluster.



In reference to the aforementioned file yaml definition 1.0 we  need to get the server endpoint(line 4): <endpoint-url> in reference to below picture pay attention to Api server endpoint and the certificate-authority-data(line 5): <base64-encoded-ca-cert> in reference to below picture have a look to Certificate Authority

















This is just the configuration process,  you will need to modify the kubeconfig file (~/.kube/config) every time that you create a new cluster, it can be done by command or modifying the kubeconfig file manually. I think that you should do this process manually  at least few times  because it will help you to understand it quite well.

So you can decide, from my point of view, when I am working in Linux environment  I run  eksctl for cluster creation process but when I am working in OS X, I prefer to create the cluster and worker nodes through the aws console, it is just an opinion. So in that case(OS X) I don't install aws CLI. It is enough with  ~/.kube/config, ~/.aws/credentials and the installation of aws-iam-authenticator.

Kubernetes from scratch for developers

miércoles, 28 de noviembre de 2018

Trying to explain Kubernetes from scratch I bring you here a guide about how make a very fruitful study of it. This thoughts are from a software developer perspective. It's not complicate and is quite well explained in Kubernetes(k8s) documentation.

My FIRST ADVICE is before beginning the study of k8s: you should study in-depth about any application container engine, I suggest docker but there are many others like rkt, runc or any other that follows OCI  specifications.
If you feel comfortable in Docker, keep going, in any other situation you will need to get some skills, it can be done by yourself. As a developer it won't be too complicated:
  • the documentation site can guide you with several examples and practical tasks.  
  • docker free lab is very useful too, easy and intuitive and mainly it encompasses the whole learning process in Docker. 
ONCE that we know at least the most important  aspects related with container engine let’s start.

At this point should be obvious for everyone concepts like Cluster or Node
So first things to know:
  1. What k8s really is? It is an open source system for managing containerized applications across multiple hosts, providing basic mechanisms for deployment, maintenance and scaling of applications. 
  2. The components of k8s 


















The previous pictures show us the basic infrastructure BUT where are the containers?. Our target is to deploy and finally run applications that are living in our containers. Our containers are living into the k8s PODs. These PODs are the basic building block in k8s and the most important aspects in this process are our applications hosted in our containers and living in those PODs at the same time.

Because our target is to deploy and finally run applications this is the whole picture that we have at this point:

A Cluster: that contains NODEs [1 Master - 1.. n Worker]
Worker Nodes: Contain : PODs
PODs: Contain: Containers
Containers: It contains applications with their own environments.

































In the previous picture there are some elements that I haven't mentioned yet (volume), I will talk about it in next posts but you can get the idea that the POD's volume is similar at docker container volume in Docker.
These PODs are living in NODEs, but which NODEs? Who decides which node spin up an specific POD?
If we take a look at the Master Node components we can see kube-scheduler, it is responsible for creating a POD in a specific node. The kube-scheduler watches newly created PODs that have no node assigned, and selects a node for them to run on, this process is not so simple, many factors taken into account for scheduling decisions include individual and collective resource requirements. In next posts we'll see that scheduler behavior can be changed and how some times you can choose in what node your POD can spin up.

There are several way for POD creations BUT all of them involve a reference to  images running on containers.
From the developer’s point of view is too easy understand k8s PODs creations process, it has two main components:
  • controller
  • custom resource definition
and third aspect is how can we talk to the cluster, k8s lets to do that by different ways:
So it is up to you, if your are familiar with RESTful environment you can access through the k8s REST API. The API is documented through Swagger so you will have an interface or apply a curl with the proper command.

In this case I am going to use the command line interface (kubectl) that  will be running commands against Kubernetes cluster.

kubectl syntax: kubectl [command] [TYPE] [NAME] [flags]

kubectl + creations commands + definition document 

Every time that the above statement take place the object defined in our definition document must be validated by kube-apiserver before configure data to any api objects(pods, services, replicationcontrollers, and others)

creations commands(to create api objects):
definition document: a custom resource definition[yaml or json document] that should describe a Controller used during the creation process. In our case our target is the POD creation.
In k8s, a Controller is a control loop that watches the shared state of the cluster through the apiserver and makes changes attempting to move the current state towards the desired state in this case we are talking about our desired state, it will be a POD.

Let's see some definition document examples and its relations with the creation commands

# nginx-deployment.yaml document describe a desired state in a Deployment object, and the Deployment controller changes the actual state to the desired state at a controlled rate. 

create -f https://raw.githubusercontent.com/ldipotetjob/k8straining/develop/yamldefinitions/nginx-deployment.yaml

# nginx-repcontroller.yaml describe a ReplicationController object

create -f https://raw.githubusercontent.com/ldipotetjob/k8straining/develop/yamldefinitions/nginx-repcontroller.yaml

Some yaml definitions documents examples

Every thing done here is from a software developer perspective so in the same way when we are going to implement our project:
  1. Local projects/environments: means create/run everything in local. 
  2. Production projects/environments: means upload to cloud environment created by ourselves or by a certified provider. 
For implement Local projects/environments previously indicated we have several options:
  1. the online training platforms[katacoda], some time run too slow but if fine just for test.
  2. install a local environment, it is very easy with minikube. It is a configurable environment that let you a simulation of a k8s cluster.
  3. install k8s in your bare metal/laptop. 
I want to give you some interesting and important reference links for the work with k8s:
  1. whole references of kubectl command line [you can find here examples about how to use a kubectl command with its flags and arguments]
  2. kubectl Cheat Sheet
Is very important to know that as a developer docker & kubernetes must be familiar for us. Do not try to memorize commands or sintaxis. Try to understand how the whole system works, the idea. Dive in K8s documentation in an ordered way. The following topics are a very good starting point:
  1. Kubernetes architecture 
  2. Containers 
  3. Workloads(Pods and Controllers)

The aforementioned aspects are physical and logical objects, to enable that every thing can work together I will need some abstract aspects for example services. In next posts I am going to review in-depth k8s services and its relationship with the rest of k8s elements.