23 Haziran 2022 Perşembe

kubectl wait seçeneği

Giriş
--for condition = available deployment şeklinde kullanılır

Örnek
Şöyle yaparız
# Add the Repo
helm repo add datawire https://app.getambassador.io helm repo update # Create Namespace kubectl create namespace emissary && \ kubectl apply -f https://app.getambassador.io/yaml/emissary/2.2.2/emissary-crds.yaml kubectl wait --timeout=90s --for=condition=available deployment emissary-apiext \ -n emissary-system # Install helm install emissary-ingress --namespace emissary datawire/emissary-ingress && \ kubectl -n emissary wait --for condition=available --timeout=90s deploy \ -lapp.kubernetes.io/instance=emissary-ingress

3 Haziran 2022 Cuma

Kubernetes kind : Deployment

Giriş
Bu yaml yerine kubectl create deployment komutu kullanılabilir.
Deployment'ı geri almak için kubectl rollout undo  komutu kullanılabilir.

Deployment Nedir
Açıklaması şöyle. Yani kaç tane pod istediğimizi vs belirtiriz.
Although pods are the basic unit of computation in Kubernetes, they are not typically directly launched on a cluster. Instead, pods are usually managed by one more layer of abstraction: the deployment.

A deployment’s primary purpose is to declare how many replicas of a pod should be running at a time. When a deployment is added to the cluster, it will automatically spin up the requested number of pods, and then monitor them. If a pod dies, the deployment will automatically re-create it.

Using a deployment, you don’t have to deal with pods manually. You can just declare the desired state of the system, and it will be managed for you automatically.
Deployment Ne Zaman Değişmiş Kabul Edilir
Açıklaması şöyle
A Deployment’s rollout is triggered if and only if the Deployment’s pod template (i.e, .spec.template) is modified. If you modify the scaling parameter, it will not rollout, but if you are changing the deployment labels or container images info, it will trigger the deployment rollout to update it.

kind : Deployment vs kind : Pod
Deployment kullanılırsa, eğer pod kapanırsa tekrar başlatılır. Pod kullanılırsa tekrar başlatılmaz. Kubernetes kind : Pod yazısına bakabilirsiniz.

Deployment Name Uzunluğu
metadata/name altınındaki string uzunluğu en fazla 47 karakter olsa iyi olur. Açıklaması şöyle. Yani aslında 253 karaktere kadar deployment name olabiliyor.
Most Kubernetes objects, including Deployments, can have names that are ≤ 253 characters in length. You should, however, consider restricting your Deployment names to ≤ 47 characters because of the implications that exceeding this threshold will have on your Pod names.
Sebebi şöyle. Yani deployment name kullanılarak ReplicaSet ve ondan da Pod ismi türetiliyor.
As you likely know, Deployments create ReplicaSets — and those ReplicaSets create Pods. When Deployment names are short (e.g. mydeployment), the ReplicaSet name is the Deployment name with a suffix of a dash/hyphen followed by the pod-template-hash, which is 9 hexadecimal characters (e.g. mydeployment–548f955bf). The Pod name is the ReplicaSet name with a suffix of a dash/hyphen followed by 5 random hexadecimal characters (e.g. mydeployment–548f955bf-j8wng).

This is convenient because it allows you to easily see which Pods correspond to which ReplicaSets as well as which Deployments simply by looking at their names, while at the same time guaranteeing uniqueness of both the Pod and ReplicaSet names.
Eğer deployment ismi 47 karakterden fazlaysa ReplicaSet ve Pod isimleri de kırpılmaya başlıyor.

spec/containers Alanı
spec/containers içinde tüm container'lar tanımlanabiliyor. Aynı şey "kind : Pod" içinde de yapılabiliyor
Örnek
Şöyle yaparız. 4 replica içren nginx çalıştırılıyor
apiVersion: v1
kind: Service metadata: name: my-nginx-svc labels: app: nginx spec: type: LoadBalancer ports: - port: 80 selector: app: nginx --- apiVersion: apps/v1 kind: Deployment metadata: name: my-nginx labels: app: nginx spec: replicas: 4 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
Örnek
Şöyle yaparız. Burada container için env de tanımlanıyor
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: europe-west4-docker.pkg.dev/...
          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"
Örnek
Şöyle yaparız. Burada container için command tanımlanıyor
apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-deployment-name
spec:
  replicas: 1
  selector:
    matchLabels:
      app: your-app-name
  template:
    metadata:
      labels:
        app: your-app-name
    spec:
      containers:
      - name: your-container-name
        image: your-image-name
        command: ["./your-executable-name","-Djavax.net.ssl.trustStore=/opt/certs/truststore.jks","-Djavax.net.ssl.trustStorePassword=changeit"]
        ports:
        - containerPort: 9092
spec/containers/resources Alanı
Kubernetes Resource Requirements yazısına taşıdım

.spec.minReadySeconds = 30
Açıklaması şöyle
The Kubernetes deployment specification allows us to set a minimum amount of time that a new pod must be in the ready state before it starts terminating the old pod. 

spec/selector/matchLabesl Alanı
matchLabels Alanı yazısına taşıdım

spec/restartPolicy Alanı
Açıklaması şöyle
Always means that the container will be restarted even if it exited with a zero exit code (i.e. successfully). This is useful when you don't care why the container exited, you just want to make sure that it is always running (e.g. a web server). This is the default.

OnFailure means that the container will only be restarted if it exited with a non-zero exit code (i.e. something went wrong). This is useful when you want accomplish a certain task with the pod, and ensure that it completes successfully - if it doesn't it will be restarted until it does.

Never means that the container will not be restarted regardless of why it exited.
Örnek
Şöyle yaparız. Burada Kafka sunucusunun sürekli çalışması istendiği için "restartPolicy: Always" kullanılıyor
kind: Deployment
apiVersion: apps/v1
metadata:
  name: example-kafka
  namespace: kafka-example
  labels:
    app: example-kafka
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example-kafka
  template:
    metadata:
      labels:
        app: example-kafka
    spec:
      containers:
        - name: example-kafka
          image: 'wurstmeister/kafka:2.12-2.4.0'
          ports:
            - containerPort: 9093
              protocol: TCP
            - containerPort: 9092
              protocol: TCP
          env:
            - name: KAFKA_ADVERTISED_LISTENERS
              value: INTERNAL://:9092,EXTERNAL://example-kafka.kafka-example.svc.cluster.local:9093
            - name: KAFKA_CREATE_TOPICS
              value: example-topic:1:1
            - name: KAFKA_INTER_BROKER_LISTENER_NAME
              value: INTERNAL
            - name: KAFKA_LISTENERS
              value: INTERNAL://:9092,EXTERNAL://:9093
            - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
              value: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
            - name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
              value: '1'
            - name: KAFKA_ZOOKEEPER_CONNECT
              value: example-zookeeper.kafka-example.svc.cluster.local:2181
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      dnsPolicy: ClusterFirst
      schedulerName: default-scheduler
      enableServiceLinks: true
  strategy:
    type: RollingUpdate

Strategy Alanı
Deployment Strategy yazısına taşıdım

imagePullPolicy Alanı
IfNotPresent değerini alabilir. Şöyle yaparız
apiVersion: apps/v1
kind: Deployment # Kubernetes resource kind we are creating
metadata:
 name: spring-boot-k8s
spec:
 selector:
   matchLabels:
     app: spring-boot-k8s
 replicas: 2 # Number of replicas that will be created for this deployment
 template:
   metadata:
     labels:
       app: spring-boot-k8s
 spec:
   containers:
      — name: spring-boot-k8s
        image: springboot-k8s-example:1.0 
           # Image that will be used to containers in the cluster
           imagePullPolicy: IfNotPresent
        ports:
          — containerPort: 8080 
          # The port that the container is running on in the cluster
terminationGracePeriodSeconds Alanı
terminationGracePeriodSeconds alanı yazısına taşıdım

Cluster Propotional Autoscaler - ReplicaSet Ekler/Siler

Giriş Açıklaması şöyle CPA aims to horizontally scale the number of Pod replicas based on the cluster’s scale. A common example is DNS ser...