19 Mayıs 2022 Perşembe

minikube start seçeneği

--driver seçeneği
Örnek
Şöyle yaparız
$ minikube start --driver=docker
--nodes seçeneği
Normalde 1 node ile başlar. Sayısı artırmak mümkün.

Örnek
Şöyle yaparız
$ minikube start --nodes 3
Worker node sayısını görmek için şöyle yaparız
$ kubectl get nodes
NAME           STATUS   ROLES                  AGE   VERSION
minikube       Ready    control-plane,master   24m   v1.20.0
minikube-m02   Ready    <none>                 22m   v1.20.0
minikube-m03   Ready    <none>                 21m   v1.20.0
Bu örnekte minikube altta docker kullanıyor. Worker Node'lardan birisini durdurmak için şöyle yaparız
$ docker stop minikube-m03
--profile seçeneği
Örnek
Şöyle yaparız
minikube profile test
minikube start -p test
Örnek
Şöyle yaparız
unset KUBECONFIG    
minikube start \  
 --profile=handson-spring-boot-cloud \  
 --memory=10240 \  
 --cpus=4 \  
 --disk-size=30g \  
 --kubernetes-version=v1.20.5 \  
 --driver=docker \  
 --ports=8080:80 --ports=8443:443 \  
 --ports=30080:30080 --ports=30443:30443   
minikube profile handson-spring-boot-cloud  
  
minikube addons enable ingress  
minikube addons enable metrics-server
Açıklaması şöyle
The ports 8080 and 8443 will be used by the Ingress controller and the ports 30080 and 30443 will be used by Services of type NodePort.



kubectl expose seçeneği - Deployment/Pod İçin Service Yaratır

Giriş
Açıklaması şöyle
Expose a resource as a new Kubernetes service.

Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. [...]
Kullanım
kubectl expose deployment
kubectl expose pod

şeklinde kullanılır

1. deployment İçin
Tüm worker node'lar port açar. Pod'a erişmek için her hangi bir worker nodu'un IP adresini kullanılabilir.

Örnek - LoadBalancer
Şöyle yaparız
kubectl expose deployment your-deployment-name \ --type=LoadBalancer \ --port=80 \ --target-port=9092
Örnek
Şöyle yaparız
kubectl apply -f deployment.yaml
kubectl expose deployment web-app --type=LoadBalancer --name=web-service
Örnek - LoadBalancer
Şöyle yaparız
$ kubectl expose deployment 
  $( kubectl get deployment --selector="planetscale.com/component=vtgate" 
  -o=jsonpath="{.items..metadata.name}" ) 
  --type=LoadBalancer 
  --name=test-vtgate 
  --port 3306 
  --target-port 3306

$ kubectl get service test-vtgate
------
NAME         TYPE          CLUSTER-IP      EXTERNAL-IP      PORT(S)         AGE
test-vtgate  LoadBalancer  [cluster_ip]    [external_ip]    3306:32157/TCP  90s
2. pod İçin
Sadece tek bir pod'a port açar. Pod'a erişmek için bu pod'un çalıştığı worker node'un IP adresini kullanmak gerekir.

Örnek
Şöyle yaparız. nodePort numarası otomatik olarak veriliyor.
kubectl expose pod rabbitmq-0 --port=15672 --target-port=15672 --type=NodePort
Örnek - nodePort
Şöyle yaparız. Dahili 12340 portu dışarıya 30869 olarak açılır. nodePort numarası otomatik olarak veriliyor.
kubectl expose pod rlwy-proc-blue-6db5798f55-m2fmp --port=12340 --target-port=12340
  --type=NodePort --name imgw1
servisin detayları şöyledir. Burada IP: 172.30.135.252 yazıyor ama aslında bu IP adresi kullanılamaz. Bu pod'un çalıştığı worker node'un IP adresini kullanmak gerekir.
$  kubectl describe svc imgw1
Name:                     imgw1
Namespace:                rlwy-04
Labels:                   app=oce-rlwy-proc
                          chartColor=blue
                          ne=rlwy
                          pod-template-hash=6db5798f55
                          processingGroup=true
                          release=rlwy-04-oce-rlwy-proc-blue
                          runsCommManager=true
Annotations:              <none>
Selector:                 app=oce-rlwy-proc,...
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       172.30.135.252
IPs:                      172.30.135.252
Port:                     <unset>  12340/TCP
TargetPort:               12340/TCP
NodePort:                 <unset>  30869/TCP
Endpoints:                10.130.4.19:12340
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
Örnek - LoadBalancer
Bunu denemedim ama tahminen şöyle yaparız. Böylece bir pod dış dünyaya açılır
kubectl expose pod rlwy-proc-blue-6db5798f55-m2fmp --port=12340 --target-port=12340
--type=LoadBalancer --name imgw1 -n rlwy-04
servise bakınca şöyledir
$ kubectl get svc
NAME   TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)
imgw1  LoadBalancer   172.30.8.31      104.198.194.171  12340:31762/TCP
servisin detayları şöyledir
$ kubectl describe svc imgw1
Name:                     imgw1
Namespace:                rlwy-04
Labels:                   app=oce-rlwy-proc
                          chartColor=blue
                          ne=rlwy
                          pod-template-hash=6db5798f55
                          processingGroup=true
                          release=rlwy-04-oce-rlwy-proc-blue
                          runsCommManager=true
Annotations:              <none>
Selector:                 app=oce-rlwy-proc,chartColor=blue,...
Type:                     LoadBalancer
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       172.30.8.31
IPs:                      172.30.8.31
LoadBalancer Ingress:     104.198.194.171
Port:                     <unset>  12340/TCP
TargetPort:               12340/TCP
NodePort:                 <unset>  31762/TCP
Endpoints:                10.130.4.19:12340
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age    From                Message
  ----    ------                ----   ----                -------
  Normal  EnsuringLoadBalancer  8m4s   service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   7m31s  service-controller  Ensured load balancer
Örnek - LoadBalancer
Şöyle yaparız
kubectl expose pod odsa-spring --type LoadBalancer --port 80 --target-port 8080

kubectl config use-context seçeneği - Named Cluster Multitenancy İçin Kullanılabilir

Giriş
Açıklaması şöyle. Yani context Kubernetes cluster'dan biraz daha fazla bir şeyi temsil ediyor. Context multitenancy için kullanılabilir.
A context is a combination of the following:
  • A Kubernetes cluster
  • Authentication information for a user
  • A default namespace
Açıklaması şöyle
By default, contexts are saved in the ~/.kube/config file, but the file can be changed using the KUBECONFIG environment variable. In this book, we will use the default location, so we will unset KUBECONFIG using the unset KUBECONFIG command.
Context vs Namespace
Context içinde farklı namespace olabilir

Context vs Cluster
Şöyle yaparız
>kubectl config get-clusters
NAME
minikube

Şimdiki Context'i Görmek
Örnek
Şöyle yaparız
kubectl config current-context
Context Listeme
kubectl config get-contexts yazısına taşıdım

Context Değiştirme
Örnek
Şöyle yaparız
kubectl config use-context gke_vitess-kubecon_europe-west_goodest-doggo-euwest4
Context Güncelleme
Örnek
Açıklaması şöyle
For example, to change the default namespace of the current context to my-namespace, use the following command:
In this command, kubectl config current-context is used to get the name of the current context.
Şöyle yaparız
kubectl config set-context $(kubectl config current-context) 
  --namespace my-namespace
Örnek
Şöyle yaparız. Burada yeni bir kullanıcı ve context yaratılıyor. 
$ kubectl config set-credentials rohan --client-certificate=rohan.crt 
  --client-key=rohan.key
User "rohan" set

$ kubectl config set-context rohan-context --cluster=minikube --namespace=space1 
  --user=rohan
Context "rohan-context" created
Yeni kullanıcıya role yaratıp bunları atıyoruz.
$ kubectl create role rohan-marketingweb --verb=get,list,update 
  --resource=pods,deployment,replicasets --namespace space1
role.rbac.authorization.k8s.io/rohan-marketingweb created

$ kubectl create rolebinding rohan-marketingweb-rolebinding --role=rohan-marketingweb
  --user=rohan --naspace space1
rolebinding.rbac.authorization.k8s.io/rohan-marketingweb-rolebinding created
Yeni context'e geçiyoruz
$ kubectl config use-context rohan-context
Switched to context "rohan-context"


kubectl delete seçeneği

Giriş
Belirtilen kaynağı siler

1. Pod
Söz dizilimi şöyle
kubectl delete pod <name>
Örnek
Şöyle yaparız.
kubectl delete pod/vttablet-demo-useast1-00003003
Troubleshooting Pods deletion
Açıklaması şöyle
If you delete a pod and it keeps coming back, chances are it is being controlled by some kind of replication set.

The types of replication sets that exist are:

Replicaset: used for basic replication and by deployments.
Statefulset: used for replication where not all replicas are exactly the same.
Daemonset: used for replication across all nodes, making sure each node in your cluster runs a certain pod.
These sets define the desired number of replicas for a given pod, so if you delete a running pod controlled by one of these, they will make sure a new pod gets scheduled in its place to meet the desired replicas defined in them.
Şöyle yaparız
# To check what is controlling your pod, you can use the kubectl get pods command:


$ kubectl get pods -o custom-columns="\
NAME:.metadata.name,\
CONTROLLED BY:.metadata.ownerReferences[*].name,\
TYPE:.metadata.ownerReferences[*].kind"
Açıklaması şöyle
In cases like these, you will need to scale down / delete the source resource which will in turn terminate the pod permanently.

As mentioned above, Deployments also use Replicasets so if you see a Replicaset then you might need to scale down the Deployment and not directly the Replicaset. You can view the owner reference of the Replicaset to see if it is standalone or has a further parent element.

--all seçeneği
Örnek
Şöyle yaparız
# To delete all pods in the default namespace, you can use the --all flag as follows
kubectl delete pod --all 

# To delete all pods in another namespace, you can add the 
# -n flag (short for --namespace) followed by the name of the namespace
kubectl delete pod --all -n staging
--dry-run=server seçeneği
Açıklaması şöyle
When using labels or field selectors to delete pods, you might want to verify which pods will be deleted by your command before actually deleting them.

To perform a dry run, you can use the --dry-run=server kubectl flag
Örnek
Şöyle yaparız
kubectl delete pod -l app=nginx --dry-run=server
pod "nginx-76d6c9b8c-sj76d" deleted (server dry run)
pod "web-0" deleted (server dry run)
--field-selector seçeneği - Deleting a Pod by field selector
Açıklaması şöyle
Pods can be deleted based on certain values using the --field-selector parameter. Similarly to deleting Pods by label, the field selector is a way to delete all pods matching a certain query.
Açıklaması şöyle
The current list of available field selectors is as follows:

metadata.name - the name of the Pod
metadata.namespace - the namespace of the Pod
spec.nodeName - the name of the Node the Pod is running on
spec.restartPolicy - the restart policy of the Pod
spec.schedulerName - the name of the Scheduler in charge of deploying the Pod
spec.serviceAccountName - the name of the service account the Pod is using
spec.hostNetwork - filter based on if the Pod is connected to the host’s network
status.phase - the lifecycle phase (status) of the Pod
status.podIP - filter based on the Pod’s IP
status.nominatedNodeName - filter based on the name of the Node that is the current “nominated” candidate to schedule the Pod.

For each of these fields, you can use the == or != comparison operators to filter the Pods that will be deleted.

Örnek
Şöyle yaparız. Running durumdaki tüm pod'ları siler
kubectl delete pod --field-selector=status.phase==Running
Örnek
Şöyle yaparız. node1 üzerinde çalışan ve Unknown durumdaki tüm pod'ları siler
kubectl delete pod --field-selector status.phase==Unknown,spec.nodeName=node1

-l seçeneği - Deleting Pod By Label
Açıklaması şöyle
There are times when it is easier to delete Pods by label—this can be because the label is constant and the name of the Pod can change, for example, in a Deployment. Deleting by label is easier for automation scripts in cases like these. Another reason could be if you want to delete many different pods sharing the same label whereas each pod would have a unique name.

To delete a pod by label, you can use the --selector flag or -l flag
Örnek
Şöyle yaparız
kubectl delete pod -l app=nginx

# You can also specify multiple labels by separating them with a comma as follows:
kubectl delete pod -l app=prometheus,component=exporter

# The above command will delete any pods with both label key values:

# app: prometheus
# component: exporter
--grace-period seçeneği
Açıklaması şöyle
By default, Kubernetes will wait 30 seconds for the Pod to complete any post-run hooks and for the main process to close after receiving the signal to terminate.

If you want to give the process more (or less) time, you can use the --grace-period flag
Söz dizilimi şöyle
kubectl delete pod <name> --grace-period=<seconds>
Açıklaması şöyle
Note that, 1 is the lowest number of seconds you can wait. Setting the value to a negative number will cause the flag to be ignored. 
Örnek - force
Açıklaması şöyle
Finally, setting the flag to 0 will skip the grace period (and hooks) altogether and can only be used together with the --force flag l
Söz dizilimi şöyle
kubectl delete pod <name> --grace-period=0 --force
Açıklaması şöyle
This combination will immediately remove the pod from Kubernetes without waiting for confirmation that the pod is terminated and the containers will be sent a signal to terminate immediately. This option should be used with care, as if there is an error which causes the container to not be deleted, for example, if a core service is not responding, then the containers might continue to run in the background without you seeing them in kubernetes.
--wait seçeneği
Açıklaması şöyle
By default, the kubectl command will hang the terminal until the object is fully removed. If the object has a large grace period this might take a while and you may want to do other things in your terminal in the meantime.

To skip the wait period, you can use the --wait=false flag 
Örnek
Şöyle yaparız
kubectl delete pod web-0 --wait=false
Örnek
Şöyle yaparız
kubectl delete pod web-0 --timeout=5s
Açıklaması şöyle
The above command will wait 5 seconds (notice the s suffix for seconds) and if the pod does not close within that amount of time, the kubectl delete command will be considered as failed and will display a timeout error in your terminal. Note that, this doesn't mean that the deletion wasn’t a success—your pods will continue to terminate in the background—this only means your pods were not entirely deleted in the specified time.
2. Deployment
Örnek
Şöyle yaparız.
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-minikube --type=NodePort --port=8080
kubectl port-forward service/hello-minikube 7080:8080

kubectl get deployment hello-minikube -o yaml

kubectl delete deploy hello-minikube
Örnek
Şöyle yaparız
kubectl delete deployment spring-boot-k8s

3. Service
Örnek
Şöyle yaparız
kubectl delete service spring-boot-k8s

kubectl get all seçeneği

Giriş
Tüm kaynakları listeler. Kaynaklar deployment, pod, service vs. gibi şeylerdir.

18 Mayıs 2022 Çarşamba

Minio

mc komutu - MinIO Client
Açıklaması şöyle
MinIO Client (mc) provides a modern alternative to UNIX commands like ls, cat, cp, mirror, diff etc. It supports filesystems and Amazon S3 compatible cloud storage service (AWS Signature v2 and v4).
Örnek
Şöyle yaparız
mc ls local

10 Mayıs 2022 Salı

kubectl proxy seçeneği - API Server Çalıştırır

Giriş
Açıklaması şöyle. Eğer minikube veya kind gibi yerel bir ortam kullanıyorsak bu komu ile bir API Server çalıştırırız.  Açıklaması şöyle
To make it easy to use the curl tool to explore the API server, run the kubectl tool in proxy mode to expose an unauthenticated API server on localhost:8001
Böylece pod üzerindeki HTTP sunucusuna kolayca erişmek için kullanılır
If you want to directly access the REST API with an http client like curl or wget, or a browser, ...
Örnek
Şöyle yaparız
kubectl proxy
API Server sorgusu göndeririz. v1 ile biten sorgu daha detaylı çıktı verir
curl --location --request GET 'http://localhost:8001/api'
curl --location --request GET 'http://localhost:8001/api/v1'
curl --location --request GET 'http://localhost:8001/openapi/v2'
api Endpoint
Kısa bir çıktı verir.. api Endpoint yazısına taşıdım

v1 Endpoint
Hem namespace içinde olan hem de olmayan kaynaklar hakkında detaylı çıktı verir.

v2 Endpoint
OpenAPI çıktısı verir. Açıklaması şöyle.
OpenAPI Specification
The API server also provides information about the schema for all Kubernetes resources. The schema is represented by the Swagger syntax. We can receive the specification by running the following curl command.

curl --location --request GET 'http://localhost:8001/openapi/v2'
If we want to program a client that communicates with the API server, we can use this schema to generate a Swagger library in it.
v1 Endpoint Örnekleri
namespace içindeki kaynaklara sorgular için şöyle yaparız
# /api/v1/namespaces
curl --location --request GET 'http://localhost:8001/api/v1/namespaces'

# /api/v1/namespaces/{namespace-name}/{resource-type-name}
curl --location --request GET 'http://localhost:8001/api/v1/namespaces/kube-system/pods'

# /api/v1/namespaces/{namespace-name}/{resource-type-name}/{resource-name}
curl --location --request GET 'http://localhost:8001/api/v1/namespaces/kube-system/pods/coredns-565d847f94-bv45c'

# /api/v1/namespaces/{namespace-name}/{resource-type-name}/{resource-name}/logs
curl --location --request GET 'http://localhost:8001/api/v1/namespaces/kube-system/pods/coredns-565d847f94-bv45c/logs'
namespace içinde olmayan kaynaklara sorgular için şöyle yaparız
a# /api/v1/{resource-type-name
curl --location --request GET 'http://localhost:8001/api/v1/persistentvolumes'

# /api/v1/{resource-type-name}
curl --location --request GET 'http://localhost:8001/api/v1/persistentvolumeclaims'

# /api/v1/{resource-type-name}/{resource-name}
curl --location --request GET 'http://localhost:8001/api/v1/persistentvolumeclaims/postgres-0'
Açıklaması şöyle
Watch Operations

The API server also supports a watch API. Instead of polling in specific intervals for some updates, we can use the watch API to get low-latency updates with a single connection.

We only need to add ?watch=true as a parameter to our API server requests. After this, the API server switches into watch mode, and leaves the connection between the client and the server open.

Örnek - Pod'a Erişmek
Bundan sonra bir pod üzerindeki web sunucusuna erişmek için şöyle yaparız
http://localhost:8001/api/v1/namespaces/default/pods /adv-vitess-cluster-vttablet-az1-1330809953-8066577e:15000
Örnek  - Pod'a Erişmek
Şöyle yaparız
$ kubectl proxy
$ curl -H “Content-Type: application/json” 
  -X POST 
  — data @binding.json 
http://localhost:8001/api/v1/namespaces/default/pods/foobar-sched/binding

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ış...