18 Temmuz 2023 Salı

Amazon Web Service (AWS) eksctl komutu

Giriş
EKS ile çalışmayı kolaylaştırır. Açıklaması şöyle
We need to install the eksctl command-line utility to manage the EKS cluster and the Kubernetes command-line tool kubectl.

create cluster seçeneği
Örnek
Şöyle yaparız
> eksctl create cluster \ 
--name microservices \ 
--region eu-central-1 \ 
--node-type t2.small \ 
--nodes 2
Açıklaması şöyle
It will make a cluster with two worker nodes of type “t2.small” in the region “eu-central-1” with the name “microservice.”

In the background, eksctl uses CloudFormation to create the cluster, which usually takes 10–15 minutes. 
Açıklaması şöyle
From the output, it is evident that it has created two nodes and one node group. Also, it has saved the kubectl config file in ./.kube/config. In case you already have minikube or microk8s, you have to mention the ./.kube/config file as the kubeconfig parameter in the command.

Creating an EKS cluster will take around 15 minutes. Once the cluster is ready, you can check it with the following command:

> kubectl get nodes --kubeconfig ~/.kube/config
Örnek
Şöyle yaparız
$ eksctl create cluster \
  --name my-cluster \
  --version 1.18 \
  --region us-west-2 \
  --nodegroup-name my-nodes \
  --node-type t3.medium \
  --nodes 3
Örnek
Şöyle yaparız
$ eksctl create cluster \
 --name Democluster\
 --version <1.21> \
 --without-nodegroup
get cluster seçeneği
Örnek
Şöyle yaparız
$ eksctl get cluster


Logstash

Giriş
Açıklaması şöyle
What Is Logstash?
Logstash is an open-source data processing pipeline from Elastic. It is being used to ingest, transform, and ship data to different sources, including Elasticsearch, Kafka, flat files, etc.

Logstash pipeline includes three different processes:

  1. Input: It is the data source from which the data is collected for ingestion.
  2. Filter: It transforms (cleans up, aggregates, etc.) the data using plugins like Grok, Mutate, Date, etc.
  3. Output: Destination for ingestion (Elasticsearch, flat files, db, etc.).
logstash.conf Dosyası
Örnek - postgres to elastic
Açıklaması şöyle
Below are the prerequisites to send data using Logstash to Elastic:

1. Logstash is installed on the system with a JDBC driver for Postgres.
2. Postgres database with a table or function to sync.
3. Elasticsearch instance is running.
Şöyle yaparız. Burada incremental ingestion yapılıyor. İş schedule alanında belirtildiği gibi dakikada bir çalışıyor. tracking_column değeri "updated_at" ve tipi timestamp. Böylece sayfalayarak elastic'e veri aktarılıyor
input {
    jdbc {
        jdbc_driver_library => "c:/logstash/jdbc/postgresql.jar"
        jdbc_driver_class => "org.postgresql.Driver"
        jdbc_connection_string => "${JDBC_HOST}"
        jdbc_user => "${DB_USER}"
        jdbc_password => "${DB_PWD}"
        jdbc_paging_enabled => true
        jdbc_page_size => 1000
        schedule => "* * * * *"  # schedule to run every minute
        statement => "SELECT * FROM employee WHERE updated_at > :sql_last_value"
        use_column_value => true
        tracking_column => "updated_at"
        tracking_column_type => "timestamp"
        last_run_metadata_path => "c:/logstash/employee.tracker"
    }
}

filter {
}
    mutate {
        remove_field => ["date", "@timestamp", "host"]
    }

    # Example of parsing JSON fields if needed
    json {
         source => "first_name"
         target => "name"
    }
}

output {
    stdout { codec => json_lines }
    elasticsearch {
        hosts => ["http://localhost:9200"]
        index => "my_table_index"
        custom_headers => {
                "Authorization" => "${AUTH_KEY}"
            }
        document_id => "%{table_id}" # Unique identifier from the table
        timeout => 120
    }
}
Örnek - filebeat'ten okur
Şöyle yaparız
input {
  beats {
    port => "4561"
    host => "0.0.0.0"
  }
}

filter { }

output {
  elasticsearch {
    hosts => ["0.0.0.0:9200"]
    index => "app-logs-%{+YYYY.MM.dd}"
  }
}
Örnek - stdout + elasticsearch 
Şöyle yaparız
# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.

input {
  file {
    path => "<Log File Full Path>"
    start_position => "beginning"
  }
}

output {
 stdout {
    codec => rubydebug
  }
  elasticsearch {
    hosts => ["https://localhost:9200"]
    ssl_certificate_verification => false
    ssl => true
    index => "elkdemoindex"
    user => "elastic"
    password => "<Elastic Search Password>"
  }
}
Örnek - TCP'den okur
Şöyle yaparız
input {
    tcp {
        port => 4560
        codec => json_lines
    }
}

filter { }

output {
    
    elasticsearch {
        hosts  => ["http://elasticsearch:9200"]
        index  => "operationlog-%{app_name}-%{+YYYY-MM-dd}"
    }
    
}



5 Temmuz 2023 Çarşamba

AWS Systems Manager

Giriş
Açıklaması şöyle
With Systems Manager, users exchange their AWS credentials for temporary shell access ....
EC2 instance'ları için AWS Resource Groups içinde tag yaratarak AWS Systems Manager ile hepsine shell komutunu çalıştıran bir örnek burada

AWS Systems Manager Parameter Store
Parameter Store ayarlarına sol taraftaki menüden erişilir. Açıklaması şöyle
AWS Systems Manager Parameter Store provides secure storage and management of secrets. It allows storing of data such as passwords, database strings, Amazon Elastic Compute Cloud (Amazon EC2) instance IDs and Amazon Machine Image (AMI) IDs, and license codes as parameter values. It can store values as plain text or encrypted data.
AWS Systems Manager Parameter Store vs AWS Secrets Manager
AWS Secrets Manager daha fazla özellik sağlıyor. Örneğin secret rotation gibi.

4 Temmuz 2023 Salı

UML Package Diagram

Giriş
Açıklaması şöyle
The UML package diagram describes the structures of the designed system at the level of packages or the dependencies between the packages that make up a model.
Paketler Arası Bağımlılıklar
Bağımlılıkları gösteren bir örnek burada. Bağımlılıklar kesikli açık ok (dashed open arrow) ile gösterilir. Bağımlılıklar için stereotype etiketler kullanılabilir. Bunların bazıları şöyle
1. <<import>>
Açıklaması şöyle
One package imports the functionality of another package. Only public elements in the package will be imported.
2. <<access>>
Açıklaması şöyle
One package requires assistance from functions of another package. 
3. <<merge>>
Açıklaması şöyle. Bence extends diye adlandırılsaydı daha iyi olurdu
It is the directed relationship between 2 packages that indicates that the content of one package is extended by the contents of another package. 

AWS Transcribe

Giriş
Açıklaması şöyle
Amazon Transcribe is a service that utilizes Machine Learning models to convert speech to text automatically. It offers various features that can enhance the accuracy of the transcribed text, such as language customization, content filtering, multi-channel audio analysis, and individual speaker speech partitioning. Amazon Transcribe can be used as a standalone transcription service or to add speech-to-text capabilities to any application. You can transcribe media in real-time (streaming) or you can transcribe media files located in an Amazon S3 bucket (batch).

3 Temmuz 2023 Pazartesi

aws ecr seçeneği - Container Registry

create-repository seçeneği
--repository-name ile ismi belirtilen yeni bir repository yaratılır

Örnek
Açıklaması şöyle
The container should be published to a registry. For this end, we’ll use Amazon ECR, a managed container registry to store, share, and deploy containers in the AWS Cloud.
...
Now, for each microservice container image, we need to create an ECR repository. Please note the repository name should exactly match the container image repository name.

Here’s the command to create a repository in ECR for the Order container image:
Şöyle yaparız
> aws ecr create-repository --repository-name microservice-customer
Çıktısı şöyle
{
  "repository": {
  "repositoryArn": "arn:aws:ecr:eu-central-1:877546708265:repository/microservice-customer",
  "registryId": "877546708265",
  "repositoryName": "microservice-customer",
  "repositoryUri": "877546708265.dkr.ecr.eu-central-1.amazonaws.com/microservice-customer",
  "createdAt": "2021-03-04T00:18:33+01:00",
  "imageTagMutability": "MUTABLE",
  "imageScanningConfiguration": {
    "scanOnPush": false
  },
  "encryptionConfiguration": {
    "encryptionType": "AES256"
  }
}
Yerel image yeniden tag'lenir ve push edilir. Şöyle yaparız
> docker tag 652da8e2130b 877546708265.dkr.ecr.eu-central-1.amazonaws.com/microservice-customer:1.0.0

> aws ecr get-login-password \
  --region eu-central-1 | \
  docker login \
    --username AWS \
    --password-stdin \
    877546708265.dkr.ecr.eu-central-1.amazonaws.com

> docker push 877546708265.dkr.ecr.eu-central-1.amazonaws.com/microservice-customer:1.0.0
delete-repository seçeneği
--repository-name ile ismi belirtilen repository silinir

Örnek
Şöyle yaparız
aws ecr delete-repository --repository-name hello-app-runner --force
get-login-password seçeneği
docker veya podman ile login olup image push etmek için şifre gerekir. Şifreyi ortamdan çekmek için bu seçenek kullanılır

Örnek - docker
Login olmak için şöyle yaparız
aws ecr get-login-password --region eu-central-1 | 
docker login 
  --username AWS 
  --password-stdin 378612673110.dkr.ecr.eu-central-1.amazonaws.com/java-demo
Örnek - podman
Şöyle yaparız
# Create an ECR repository
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
export AWS_REGION=us-east-1
aws ecr create-repository --repository-name hello-app-runner

# Authenticate with an external container registry and push the generated image
podman login --username AWS --password $(aws ecr get-login-password \
     --region ${AWS_REGION}) ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
podman tag hello-app-runner:latest \
  ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/hello-app-runner:latest

H.264 Nedir? - Bir Codec Standardı

Giriş
H.264 bir codec standardı. Açıklaması şöyle. Yani video cihazından görüntüyü yakalar ve dijital hale getirir.
H.264 is one of the most popular codecs for live video streaming, and it can be used to create video files in various resolutions up to 8k.
Bu standardı gerçekleştiren farklı encoder'lar var. Farkı vurgulayan bir açıklama şöyle
Consider the case for H.264. The standard's name is H.264 – that's not the name of the actual encoder. Mainconcept is a very good commercial encoder, whereas x264 is a free and open source one. 
...
The mere fact that you can optimize encoding makes for a competition here. Both encoders will deliver a standardized bitstream that can always be decoded by a H.264-compliant decoder.
Sıkıştırma
Açıklaması şöyle. Sıkıştırma yöntemlerinden bir tanesi interframe compression. İki frame arasındaki fark gönderilir.
How does H.264 encoding work?

H.264 is a video compression standard that is commonly used to encode video files for a variety of purposes, including streaming over the internet. H.264 uses a combination of techniques to reduce the size of video files without significantly impacting the quality of the video. One of the key techniques used by H.264 is known as “interframe compression.” This technique involves analyzing the differences between consecutive frames of the video and only storing the information that has changed from one frame to the next. By storing only the differences between frames, H.264 is able to significantly reduce the amount of data that is required to represent the video. H.264 also uses techniques such as quantization, entropy coding, and motion compensation to further reduce the size of the video data. These techniques involve analyzing the video data and removing redundant or irrelevant information, as well as using advanced mathematical algorithms to represent the data more efficiently.