17 Eylül 2021 Cuma

Kubernetes Deployment İçin Volumes

Giriş
Çeşitli volume tipleri var.
1. emptyDir
2. PersistentVolume
gibi

emptyDir
Şu cümleler önemli
emptyDir are volumes that get created empty when a Pod is created.
Deleting a Pod deletes all its emptyDirs.
emptyDir are meant for temporary working disk space.

Örnek
Şöyle yaparız
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dune-quote-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dune-quote-service
  template:
    metadata:
      labels:
        app: dune-quote-service
    spec:
      containers:
        - image: gamussa/reactive-quote-service:0.0.3
          imagePullPolicy: Always
          name: dune-quote-service
          ports:
            - containerPort: 9001
          env:
            ...
            - name: GRPC_SERVER_SECURITY_CERTIFICATECHAIN
              value: "file:/mnt/grpc-cert-chain/server.crt"
            - name: GRPC_SERVER_SECURITY_PRIVATEKEY
              value: "file:/mnt/grpc-pk/server.key"
          volumeMounts:
            - mountPath: /mnt/grpc-cert-chain
              name: grpc-cert-chain
            - mountPath: /mnt/grpc-pk
              name: grpc-pk
      volumes:
        - name: grpc-cert-chain
          secret:
            secretName: grpc-cert-chain
        - name: grpc-pk
          secret:
            secretName: grpc-pk
Örnek - sadece tmp Dizini Hakkı
Açıklaması şöyle
Applications running in a containerized environment seldom write data, as that practically goes against the logic of having an immutable system. However, at times, it may be needed for caching or temporary swapping/processing of files. Hence, to provide this functionality to the developer, we can mount an emptyDir as an ephemeral volume which is lost once the container is killed.

With this in place, we can also add another security context attribute called “readOnlyRootFilesystem” and set it as true, since the application running inside the container no longer needs to write anywhere on the file-system other than the ‘tmp’ directory.
Şöyle yaparız
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: springbootmaven
  name: springbootmaven
  namespace: boot
spec:
  replicas: 1
  selector:
    matchLabels:
      app: springbootmaven
  template:
    metadata:
      labels:
        app: springbootmaven
    spec:
      securityContext:
        fsGroup: 1337
        runAsNonRoot: true
        runAsUser: 1337
      containers:
      - image: salecharohit/springbootmaven
        name: springbootmaven
        ports:
        - containerPort: 8080
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          privileged: false
          runAsUser: 1337
          capabilities:
            drop: ["SETUID", "SETGID"]
        volumeMounts:
        - mountPath: /tmp
          name: tmp
      serviceAccountName: ""
      automountServiceAccountToken: false
      volumes:
      - emptyDir: {}
        name: tmp

16 Eylül 2021 Perşembe

Kubernetes Servis Nedir?

Giriş
Açıklaması şöyle. Dış dünyaya açılan yüzümüz diye düşünebiliriz.
A Service enables network access to a set of Pods in Kubernetes.

Services select Pods based on their labels. When a network request is made to the service, it selects all Pods in the cluster matching the service's selector, chooses one of them, and forwards the network request to it.
Service ve Deployment Farkı Nedir?
Açıklaması şöyle.
A deployment is responsible for keeping a set of pods running.
A service is responsible for enabling network access to a set of pods.
Servis Tipleri Nedir?
Açıklaması şöyle
The type property in the Service's spec determines how the service is exposed to the network. It changes where a Service is able to be accessed from. The possible types are ClusterIP, NodePort, and LoadBalancer

- ClusterIP – The default value. The service is only accessible from within the Kubernetes cluster – you can’t make requests to your Pods from outside the cluster!

- NodePort – This makes the service accessible on a static port on each Node in the cluster. This means that the service can handle requests that originate from outside the cluster.

- LoadBalancer – The service becomes accessible externally through a cloud provider's load balancer functionality. GCP, AWS, Azure, and OpenStack offer this functionality. The cloud provider will create a load balancer, which then automatically routes requests to your Kubernetes Service
servisleri görmek için kubectl get services kullanılır

ClusterIP Service yazısına bakabilirsiniz
LoadBalanceService yazısına bakabilirsiniz
IngressService yazısına bakabilirsiniz


Kubernetes Pod Nedir?

Giriş
Pod, Kubernetes mimarisinde Kubernetes Node'un bir parçası. Kısaca container'ları çalıştırır deyebiliriz.

Açıklaması şöyle. Aslında bir pod birden fazla docker container çalıştırabilir. Açıklaması şöyle
The primary reason that Pods can have multiple containers is to support helper applications that assist a primary application. Typical examples of helper applications are data pullers, data pushers, and proxies. Helper and primary applications often need to communicate with each other. Typically this is done through a shared filesystem, as shown in this exercise, or through the loopback network interface, localhost. An example of this pattern is a web server along with a helper program that polls a Git repository for new updates. 
Ancak bu tavsiye edilmediği için pod = container gibi düşünülebilir.
The containers are called as ‘Pod’ in Kubernetes terms. So a single Kubernetes node can have multiple containers.
Pod örneğin bir servis olabilir.
Kubernetes Servis Nedir? yazısına bakabilirsiniz

Örnek
Buradaki şekilde aynı Pod içinde çalışan farklı container'lar görülebilir.

15 Eylül 2021 Çarşamba

chpasswd komutu

Örnek
gitlab-ci isimli kullanıcının şifresini changemepassword yapmak için şöyle yaparız
echo 'gitlab-ci:changemepassword' | chpasswd

anacron

Giriş
Açıklaması şöyle
On many systems, if you turn your computer off at night and boot it or wake it up from suspension in the morning, it'll run various daily jobs, via anacron. This starts a few minutes after the computer wakes up, so you'd typically have time to log in but the resource usage would intensify after a few minutes. Anacron jobs are configured in /etc/anacrontab; a common configuration is for it to run the jobs listed in /etc/cron.daily. Maybe one of these jobs is using an unreasonable amount of resources for some reason. Use a tool like pstree to check what children of anacron are running.

13 Eylül 2021 Pazartesi

Kubernetes Configuration Examples

Giriş
Konfigürasyon için iki yöntem var
1. Environment variable
2. ConfigMap
Her iki yöntem de Pod, Service veya herhangi bir başka Kubernetes kind için kullanılabilir.

1. Environment variable
env başlığı altında
- name + value 
- name + valueFrom + configMapKeyRef
- name + valueFrom + secretKeyRef
şeklinde kullanılır

Örnek
Şöyle yaparız
apiVersion: v1
kind: Pod
metadata:
  name: static-web
  labels:
    role: myrole
spec:
  containers:
  - name: nginx
    image: nginx
    env:
    - name: DB_NAME
      value: MyDB
    - name: DB_URL
      valueFrom:
        configMapKeyRef:
          name: config-url
          key: db_url
    - name: DB_PASSWORD
      valueFrom:
        secretKeyRef:
          name: config-passwd
          key: db_password
2. ConfigMap
Kubernetes ConfigMap yazısına taşıdım

12 Eylül 2021 Pazar