8 Ekim 2021 Cuma

Kubernetes Ingress Service

Giriş
Açıklaması şöyle. OpenShift terminolojisinde Ingress yerine Route kelimesi kullanılıyor.
Ingress is actually NOT a type of service. Instead, it sits in front of multiple services and act as a “smart router” or entrypoint into your cluster.
Şeklen şöyle. Burada ingress olarak nginx kullanılıyor.


Örnek
Şöyle yaparız
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
   ingress.kubernetes.io/rewrite-target: /
 name: web-ingress
spec:
  rules:
  - host: kubernetes.foo.bar
    http:
      paths:
      - backend:
          serviceName: appsvc
          servicePort: 80
        path: /app
Daha sonra /etc/nginx.conf şöyle yaparız
server {
    server_name kubernetes.foo.bar;
    ...
}

7 Ekim 2021 Perşembe

Helm - The Kubernetes Package Manager

Helm Nedir
Açıklaması şöyle
Helm is a software package manager similar to the DNF package manager in Fedora and the Windows Package Manager. Package managers allow developers to install software tools and maintain them (e.g., upgrade, delete, and patch) quickly using a command-line interface or graphical user interface (GUI).

Developers can install a particular collection of files representing Kubernetes resources by using a Helm chart. When the chart is installed, it is managed by a release. The developer can delete or upgrade the release on demand to make application deployment changes.
Açıklaması şöyle
The deployment of a microservice to a K8s cluster might become challenging as it is related to creating a number of various K8s resources such as pods, replica sets, services, config maps, secrets, etc. Helm helps with that.
Nasıl Çalışır
Açıklaması şöyle. Yani Helm ile değişkenler farklı bir yaml dosyasında tanımlanıyor. Helm bu değerleri şablon yalm dosyalarında kullanıyor
The basic idea of Helm is to enable reusability of Kubernetes YAML artifacts through templatization. Helm allows defining Kubernetes YAMLs with marked up properties. The actual values for these properties are defined in a separate file. Helm takes the templatized YAMLs and the values file and merges them before deploying the merged YAMLs into a cluster. The package consisting of templatized Kubernetes YAMLs and the values file is called a ‘Helm chart’. Helm project has gained considerable popularity as it solves one of the key problems that enterprises face — creating custom YAMLs for deploying the same application workload with different settings, or deploying it in different environments (dev/test/prod).
Kurulum
Şöyle yaparız
# Linux - Çalışmıyor
sudo snap install helm --classic

# Mac
brew install kubernetes-helm

# Windows - Çalışıyor
choco install kubernetes-helm
Helm 2 vs Helm 3
Açıklaması şöyle
Helm had major shift from server-side architecture (Helm v2) to client-side architecture (Helm v3). Tiller was the server-side component that managed Helm Charts and later it moved to a client-side model where all operations are perform via the Helm 3 CLI while relying on k8s RBAC for authorization and security features.
Şeklen şöyle Yani Tiller bileşeni kaldırılmış


Genel Kullanım
Örnek
Şöyle yaparız
helm create ...
helm upgrade ...
helm history ...
Örnek
Şöyle yaparız
helm create helm-myapp
helm lint helm-myapp
helm package helm-myapp helm install helm-myapp-0.1.0.tgz helm list
Şeklen şöyle


Chart
Helm terminolojisinde bir uygulamayı kubernetes'e kurmak için gereken tüm farklı kubernetes kaynaklarını temsil eder. Deployment + Service + Volume vs. gibi. Bunları hepsi bir chart altında toplanır

helm komutu yazısına bakabilirsiniz

Helm Chart Repositories
Açıklaması şöyle
A Helm chart repositories or REPO is a simple HTTP site that serves an index.yaml file and .tar.gz packaged charts. The helm command has subcommands available to help package charts and create the required index.yaml file. These files can be served by any web server, object storage service, or a static site host such as GitHub Pages.

Helm normally comes with pre-defined Charts which can be found Git Hub Repository

Alternate repos can be added with the helm repo add command. Some popular alternate repositories are Bitnami Helm Charts which provide some charts that aren’t covered in the official stable repo.
Örnek
Şöyle yaparız
$ mkdir charts
$ helm package ansible -d charts
Successfully packaged chart and saved it to: charts\ansible-0.1.tgz

$ helm repo index charts

index.yaml şöyledir
apiVersion: v1
entries:
  ansible:
  - apiVersion: v1
    appVersion: "1.1"
    created: "2021-08-02T10:25:28.8208129+05:30"
    description: Helm Chart for Ansible.
    digest: 7f02792923971dbdbc0478bc3180ee7cd6ea3623bb1c5666d6a827c62ee6560d
    name: ansible
    urls:
    - ansible-0.1.tgz
    version: "0.1"
generated: "2021-08-02T10:25:28.7883963+05:30"


3 Ekim 2021 Pazar

clock_gettime metodu

Giriş
Şu satırı dahil ederiz.
#include <time.h>
clock_gettime ile birçok saat çeşidi gelmektedir.
Açıklaması şöyle
POSIX only requires that CLOCK_REALTIME be present, other clocks are optional.
Monotonic Saat - CLOCK_MONOTONIC
Örnek
Şöyle yaparız
clock_gettime(CLOCK_MONOTONIC, & spec);
Örnek
Şöyle yaparız.
struct timespec start, end;
for(i = 0; i < pkt_count; ++i)
{

  clock_gettime(CLOCK_MONOTONIC, &start);        
  ...
  clock_gettime(CLOCK_MONOTONIC, &end);        

  printf("%.3f ", timespec_diff_usec(&end, &start));
}   
timespec_diff_usec() metodu burada tanmlı.

Monotonic Saat - CLOCK_MONOTONIC_RAW
CLOCK_MONOTONIC_RAW Linux'a mahsus bir saat ve direkt donanımla konuştuğu yazılı ancak bu cümleden tam ne kast ediliyor bilmiyorum.
Örnek
Şöyle yaparız.
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
Sistem Saati - CLOCK_REALTIME
Epoch'tan beri geçen süreyi yani UTC saati almak için CLOCK_REALTIME saatini kullanmak gerekir. Bu metod ile saniye + nanosaniye seviyesinde ölçüm yapmak mümkündür. Yani gettimeofday metoduna göre daha hassastır.
Bu metod sonucu ikinci parametre olan struct timespec'i doldurarak verir.
Örnek
Şöyle yaparız
#include <unistd.h>
#include <time.h>

int main()
{
    // Çıktı olarak 876,764,530 saniye döner
    printf("time returns %d seconds\n", time(NULL);)
   
    //Çıktı olarak 876,764,530 saniye 000,0674,633 nanosaniye döner
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME, &ts);
    printf("%d seconds and %ld nanoseconds\n", ts.tv_sec, ts.tv_nsec);
}
Örnek
Bir başka örnekte ise sistemin verdiği saati 5 saniye ileri alınıyor.
struct timespec start;
clock_gettime(CLOCK_REALTIME, &start); start.tv_sec+=5; //5 saniye ileri al
Örnek
Şöyle yaparız.
struct timespec  ts;

if (clock_gettime(CLOCK_REALTIME, &ts))
{
  ...  
}
Örnek
clock_gettime POSIX eş zamanlılık API'leri ile kullanılır. Şöyle yaparız.
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 10; // ten seconds
while (!my_condition && ret == 0)
  ret = pthread_cond_timedwait (&cond, &mutex, &ts);
Kullanılan CPU Saati - CLOCK_PROCESS_CPUTIME_ID
Açıklaması şöyle. Uygulamanın kullandığı CPU zamanını ölçer.
Most operating systems have some clocks that will only count while your process is running. These are not standardized, but on POSIX systems you could consider using clock_gettime() with CLOCK_PROCESS_CPUTIME_ID.
Örnek
Şöyle yaparız
timespec time1, time2;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
...
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);


2 Ekim 2021 Cumartesi

groupdel komutu - Group Siler

-h seçeneği
Seçenekler şöyle
-h --help
-R --root CHRROT_DIR
 -P, --prefix PREFIX_DIR
-f --force

dpkg-reconfigure komutu

Giriş
Ubuntu'da kullanılır

Örnek
Şöyle yaparız
sudo dpkg-reconfigure ca-certificates

openssl s_client aracı - Sertifikaları Görüntüler

Giriş
Sertifikaları görüntüler. Aynı işi tarayıcımız ile de yapabiliriz. Bu araç TLS bağlantısı açar. Açıklaması şöyle.
Also be aware s_client displays in decoded form only the Subject field of the cert (and Issuer, as s: and i: respectively), but not the SubjectAlt[ernative]Name aka SAN extension which is used for the hostname(s) of an SSL/TLS server cert since about the beginning of this century. 
-connect seçeneği
Örnek
Şöylee yaparız.
echo -n | openssl s_client -showcerts -connect website.com:443 -servername website.com
-showcerts seçeneği
Örnek
Sunucunun gönderdiği sertifikayı görmek için şöyle yaparız.
openssl s_client -connect target.server.com:443 -showcerts
-servername seçeneği
Bir sunucuda birden fazla sanal alan varsa kullanılır.
Örnek
Şöyle yaparız
echo | openssl s_client -showcerts -servername arturofm.com 
-connect arturofm.com:443 2>
Örnek
Sertifikadaki bir alanı görmek için şöyle yaparız
$ echo | 
  openssl s_client -servername {SERVER_NAME} -connect {SERVER_NAME}:{PORT} | 
  openssl x509 -noout -dates











28 Eylül 2021 Salı

bash kodlama $? gömülü değişkeni - Return Value

Giriş
Son çalıştırılan komutun exit status değerini verir.

Bu değişkeni Kullanmamak
Açıklaması şöyle
SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
Bir uygulamayı çalıştırıp döndürdüğü sonucu almak için şu yol izlenebilir
utility

# shellcheck disable=SC2181
if [ "$?" -eq 0 ]; then
    echo ok
else
    echo fail
fi
Ancak şöyle yapmak daha kolay
if utility; then
    echo ok
else
    echo fail
fi
Kullanma Örnekleri
Örnek
Şöyle yaparız.
another_script.sh
exit_code=$?
Örnek
Şöyle yaparız.
grep -q '/example.com' /opt/nfs || grep -Rq '/example.com' /data
if [ $? -eq 0 ]; then   # check exit status
  echo "Passed"
else 
  echo "Failed"
fi
Örnek
set -e ile ilk hata da bash'in devam etmemesi sağlanır. Ancak bazı komutların 0'dan farklı bir şey dönmesi durumunda şöyle yaparız. Böylece set -e dikkate alınmaz.
#!/usr/bin/env bash
set -e
! docker stop foo
! docker rm -f foo
# ... other stuff