9 Kasım 2022 Çarşamba

helm package seçeneği - tgz uzantılı bir dosya oluşur

Giriş
Helm Chart'ı paketler ve . tgz uzantılı bir dosya oluşur

Örnek
Şöyle yaparız
helm package helm-myapp
Örnek
Şöyle yaparız
>> helm package  demo-chart
---------------------------------------------------------------
Successfully packaged chart and saved it to: /home/ec2-user/chart/demo-chart-0.1.0.tgz
Diğer
Normalde paketleme için Chart.yaml dosyasındaki değerler kullanılır. Bunları ezilebilir

Örnek --version
Şöyle  yaparız
>> helm package [CHART_PATH]      [FLAG]
>> helm package  demo-chart --version 1.1
---------------------------------------------------------------
Successfully packaged chart and saved it to: /home/ec2-user/chart/demo-chart-1.1.tgz

Örnek --version + --app-version + --destionation
Şöyle  yaparız
>> helm package demo-chart \
   --version 1.1 \
   --app-version "latest" \
   --destination ~/helm
---------------------------------------------------------------
Successfully packaged chart and saved it to: /home/ec2-user/helm/demo-chart-1.1.tgz

helm create seçeneği - Yeni Proje Oluşturur

Giriş
Yeni proje oluşturur

Örnek
Şöyle yaparız
helm create mychart
Oluşturulan dosya ve dizinler şöyle.
mychart/
  Chart.yaml - Chart'ın tanımını içerir
  values.yaml - Varsayılan değerleri içerir
  charts/
  templates/
  ...
Dizin yapısı şöyle
go-k8s
|-- Chart.yaml
|-- charts
|-- templates
|   |-- NOTES.txt
|   |-- _helpers.tpl
|   |-- deployment.yaml
|   |-- ingress.yaml
|   `-- service.yaml
`-- values.yaml

Örnek
Şöyle yaparız
> helm create  demo-chart
Çıktısı şöyle
>> tree demo-chart
demo-chart
├── charts
├── Chart.yaml  # Information about your chart
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml    
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

1. .helmignore Dosyası
Açıklaması şöyle. Projeyi oluşturunca bu dosya da otomatik olarak yaratılır.
There may be cases where we need to ignore some files from the chart directory while creating the packaged version. In that case, we can create a file named .helmignore under the chart directory. And then we can populate the .helmignore file with the patterns or names of files to be ignored during the creation of a packaged version of the chart.

For instance, Let’s assume we want to ignore ingress.yaml residing under the templates directory.

>> cd demo-chart
>> vim .helmignore
# Add the folloing line into the .helmignore file
---
ingress.yaml   
And now, create the packaged version of the chart :

>> helm package demo-chart --version 1.2
---------------------------------------------------------------
Successfully packaged chart and saved it to: /home/ec2-user/chart/demo-chart-1.2.tgz
Örnek
Şöyle yaparız
For instance, Let’s assume we want to ignore ingress.yaml residing under the templates directory.

>> cd demo-chart
>> vim .helmignore
# Add the folloing line into the .helmignore file
---
ingress.yaml   
And now, create the packaged version of the chart :

>> helm package demo-chart --version 1.2
---------------------------------------------------------------
Successfully packaged chart and saved it to: /home/ec2-user/chart/demo-chart-1.2.tgz
2. Chart.yaml Dosyası
Açıklaması şöyle
charts directory contains the charts that the corresponding chart depends on.

Chart.yaml contains the metadata of the corresponding chart.
Bu dosyada version ve appVersion diye iki tane alan var. Açıklaması şöyle
Each Helm chart comes with 2 separate versions:
  1. Chart version itself [version inChart.yaml]
  2. Application version in chart [appVersion in Chart.yaml]
2. values.yaml Dosyası
Açıklaması şöyle. Yani template dosyalarında kullanılacak varsayılan değerler içerir.
This file declares variables to be passed into the templates. Modify the file to include your Docker image, tag, and service name, ports, type, and database values
Açıklaması şöyle. Eğer bazı değerleri ezmek istersek --values veya --set seçenekleri ile yapılabilir.
values.yaml contains the default values, which will be used to generate k8s manifest files residing under the template directory. The default values can be overwritten using the —values or — set command during the installation of a chart.
3. templates dizini
Açıklaması şöyle
templates contain all the manifest files that will be used to create k8s objects. Such as — deployment, service account, and so on.
Açıklaması şöyle
The templates/ directory is for template files. When Helm evaluates a chart, it will send all of the files in the templates/ directory through the template rendering engine. It then collects the results of those templates and sends them on to Kubernetes.

The values.yaml file is also important to templates. This file contains the default values for a chart. These values may be overridden by users during helm install or helm upgrade.

The Chart.yaml file contains a description of the chart. You can access it from within a template. The charts/ directory may contain other charts (which we call subcharts). 
4. templates/_helpers.tpl dosyası
Açıklaması şöyle
_helpers.tpl contains several methods/sub-template (written in golang text templating syntax), which will be used by the YAML files residing under the templates dircetory.
 

8 Kasım 2022 Salı

Kubernetes Disaster Recovery

Giriş
Burada bir örnek var. Örnekte etcd veri tabanının yedeği alınıyor ve diğer region'a kopyalanıyor

6 Kasım 2022 Pazar

Kubernetes IDE

Giriş
kubectl komutlarını hatırlamak zor olabilir. Bezen görsel çalışmak daha kolay olabiliyor.

Cloud provider tarafından sağlanan console dışında
1. IDE olarak Lens kullanılabilir

5 Kasım 2022 Cumartesi

Kubernetes kind : ReplicaSet

Giriş
spec/selector hangi podlara uygulanacağını belirtir.
spec/template podları yaratırken kullanılacak şablonu belirtir. Örneğin spec/template/containers pod için kullanılacak image ismini belirtir.

kubectl get replicasets ile replicasetler listelenir

Örnek
Şöyle yaparız
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: frontend
  labels:
    app: guestbook
    tier: frontend
spec:
  # modify replicas according to your case
  replicas: 3
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: php-redis
        image: gcr.io/google_samples/gb-frontend:v3

3 Kasım 2022 Perşembe

Kubernetes kind: HorizontalPodAutoscaler - CPU İle Ölçekleme

Giriş
Değerler iki şekilde verilebiliyor
1. Yüzde Olarak
2. Mutlak Değer Olarak

Yüzde Olarak
targetCPUUtilizationPercentage kullanılır. Tüm podlardaki ortalama CPU kullanımını alır belirtilen yüzde ile çarpar ve resources/requests alanında belirtilen değer ile karşılaştırır

Mutlak Değer Olarak
targetAverageUtilization kullanılır. Açıklaması şöyle
When a targetAverageValue or targetAverageUtilization is specified, the currentMetricValue is computed by taking the average of the given metric across all Pods in the HorizontalPodAutoscaler's scale target.

1. Yüzde Olarak
Örnek
Yüzde olarak hesaplarken şuna dikkat etmek lazım. Yani resources bölümlü altındaki requests değeri kullanılır. limit değeri kullanılmaz
The documentation states “Utilization is the ratio between the current usage of resource to the requested resources of the pod.”
Deployment şöyle olsun.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-deployment
spec:
  template:
    spec:
      containers:
        - name: hello-world
          image: helloworld-webserver:v1.0.0
          resources:
            requests:
              cpu: 10m
              memory: 32Mi
            limits:
              cpu: 100m
              memory: 64Mi
              ...
HPA şöyle olsun. Burada yüzde olarak belirtirsek 10m değeri dikkate alınır. Eğer ortalama 8m'nin üzerine çıkarsa HPA çalışır
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: helloworld-deployment
spec:
  maxReplicas: 4
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: helloworld-deployment
  targetCPUUtilizationPercentage: 80
Açıklaması şöyle. 
Your HPA will start scaling the replicas up when average CPU utilization exceeds 8m, not 80m.

If you wanted your HPA to allow CPU utilization greater than the request before scaling up, you can simply specify a target utilization percentage greater than 100. In this example, to allow the utilization to reach 60m before scaling up, you could specify a target utilization percentage of 600.
2. Mutlak Değer Olarak
Örnek
Deployment şöyle olsun
apiVersion: apps/v1
kind: Deployment
metadata:
  name: order-deployment
  namespace: default
  labels:
    app: order-deployment
spec:
  selector:
    matchLabels:
      app: order-deployment
  template:
    metadata:
      labels:
        app: order-deployment
    spec:
      containers:
        - name: order-service
          image: ...
          env:
            - name: SPRING_DATASOURCE_URL
              value: "jdbc:postgresql://postgres-service:5432/postgres?currentSchema=order
          resources:
            limits:
              cpu: "500m"
              memory: "1024Mi"
            requests:
              cpu: "200m"
              memory: "256Mi"
Şöyle yaparız. Burada 200m istenmiş. Eğer ortalama 85m'nin üzerine çıkarsa HPA çalışır
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: order-deployment-hpa
  namespace: default
  labels:
    app: order-deployment
spec:
  scaleTargetRef:
    kind: Deployment
    name: order-deployment
    apiVersion: apps/v1
  minReplicas: 2
  maxReplicas: 4
  metrics:
    - type: Resource
      resource:
        name: cpu
        targetAverageUtilization: 85

Kubernetes 1.33 - Octarine

Giriş Yenilikler şöyle 1. Native Sidecar Containers 2. In-Place Pod Resizing: The End of Disruptive Scaling Artık pod'un belleğini çalış...