10 Eylül 2020 Perşembe

paste komutu - Girdileri Tek Satır Haline Getirir veya İki Belgeyi Yan Yana Gösterir

Giriş
Açıklaması şöyle. Girdileri tek satır haline Getirir veya iki belgeyi yan yana gösterir
The paste command joins two files as columns
-d seçeneği
Açıklaması şöyle
adding the flag -d' ' to your paste command will produce a space separated output
Örnek - delimiter kullanma
Elimizde şöyle bir dosya olsun
Mario
mario@me.com
+399038259953
Luigi
luigi@live.com
+395902385093
Yoshi
yoshi@yahoo.com
+81293565291
Şöyle yaparız
 paste -d,  - - - < file
Çıktı olarak şunu alırız
Mario,mario@me.com,+399038259953
Luigi,luigi@live.com,+395902385093
Yoshi,yoshi@yahoo.com,+81293565291
Örnek - İki Dosya Yan yana
Elimizde şöyle bir dosya olsun.
linux mint
ubuntu
cent-os
fedora
debian
kali linux
arch linux
kubuntu
open suse
deepin
parrot os
Elimizde şöyle bir başka dosya olsun.
linux mint
cent-os
fedora
kali linux
arch linux
kubuntu
open
deepin
parrot
ubuntu
debian
Şöyle yaparız
paste file1.txt file2.txt
Çıktı olarak şunu alırız
file1.txt                      file2.txt

linux mint                     linux mint
ubuntu                         cent-os  
cent-os                        fedora   
fedora                         kali linux    
debian                         arch linux
kali linux                     kubuntu   
arch linux                     open 
kubuntu                        deepin   
open suse                      parrot
deepin                         ubuntu
parrot os                      debian   
Örnek - İki Dosya Yan yana
Şöyle yaparız
grep ... | paste - file2
Çıktı olarak şunu alırız
dev-ops line1
pro-ops line2
qc-ops line2
Örnek - İki Dosya Yan yana
Elimizde şöyle bir dosya olsun.
1023M  BLD
945K   Deployment
4899   INT
Elimizde şöyle bir başka dosya olsun.
1.2G   BLD
345M   Deployment
499M   INT
Şöyle yaparız. Bu iki dosyayı yan yana birleştiriyor.
paste file1 file2
Çıktı olarak şunu alırız
1023M  BLD  1.2G   BLD
945K   Deployment   345M   Deployment
4899   INT  499M   INT

9 Eylül 2020 Çarşamba

bash kodlama printf built-in komutu

Giriş
printf her zaman echo komutuna tercih edilmeli

1. Unicode
Açıklaması şöyle. Unicode için \u veya \U ile başlayan karakterler kullanılır.
\uHHHH
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHH (one to four hex digits)

\UHHHHHHHH
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHHHHHH (one to eight hex digits)
Örnek
Şöyle yaparız. \U ile başlayan sayı 5 karakter.
# printf "\u2660 \u1F0A1 \U1F0A1\n"
 1 🂡
2. Renkli Çıktı
Metin Rengi
256 renk kullanılabilir.
Örnek
Şöyle yaparız
printf "\033[38;5;196mhello\n"
Arka Plan Rengi
8 renk kullanılabilir.
Örnek
Şöyle yaparız.
printf "\033[41mhello\n"
3. Formatlama Seçenekleri
Açıklaması şöyle. Yani C dili gibidir.
Arguments to non-string format specifiers are treated as C language constants, except that a leading plus or minus sign is allowed, and if the leading character is a single or double quote, the value is the ASCII value of the following character.
Tek veya çift tırnak içinde formatlanacak string formatlama seçenekleri ile belirtilir. Daha sonra da boşluk bırakılarak değişkenler verilir.

Örnek
Şöyle yaparız
$ var="Hello"
$ printf '%s\n' "$var"
Hello
%b seçeneği
Örnek
Şöyle yaparız
printf '%b\n' 'hello\nworld'
%d seçeneği
Örnek
Şöyle yaparız.
$ printf %d\\n "'a'"
97
$ printf %d\\n "'0'"
48
$ printf %d\\n "'"$'\1'
1
Örnek
Dosyadan bir sayı okuyalım.
BN=$($cat Build.number)
3 basamaklı yazdırmak için şöyle yaparız.
printf "%.3d\n" $((++BN)) > Build.number
%f seçeneği
Açıklaması şöyle.
The floating-point formatting conversion specifications of printf() are not required because all arithmetic in the shell is integer arithmetic. The awk utility performs floating-point calculations and provides its own printf function. The bc utility can perform arbitrary-precision floating-point arithmetic, but does not provide extensive formatting capabilities. (This printf utility cannot really be used to format bc output; it does not support arbitrary precision.) Implementations are encouraged to support the floating-point conversions as an extension.
Örnek
Şöyle yaparız.
printf "%.18f\n" 5.10
5.100000000000000000
%s seçeneği
Örnek
NULL ile biten string için şöyle yaparız.
printf '%s\0' small*jpg
Örnek
%s'in kaç kere kullanıldığının önemi yok. Parametre sayısı kadar tekrar edebiliyor. Şöyle yaparız. Çıktı olarak şunu alırız
$ printf "%s" a b
ab
Şöyle yaparız. Çıktı olarak şunu alırız
$ printf "%s%s" a b
ab
Escape Karakterler
Örnek - \n
Şöyle yaparız.
$ printf "hi"
hi$ printf "hi\n"
hi

7 Eylül 2020 Pazartesi

6 Eylül 2020 Pazar

kubectl komutu

Giriş
cheatsheat burada


create
Şöyle yaparız
kubectl create -f hello-world.yaml
create deploy
create deploy yazısına taşıdım

create namespace
namespace farklı policy'ler için gerekir
Bir örnek şöyle
In a scenario where an organization is using a shared Kubernetes cluster for development and production use cases:

The development team would like to maintain a space in the cluster where they can get a view on the list of Pods, Services, and Deployments they use to build and run their application. In this space, Kubernetes resources come and go, and the restrictions on who can or cannot modify resources are relaxed to enable agile development.

The operations team would like to maintain a space in the cluster where they can enforce strict procedures on who can or cannot manipulate the set of Pods, Services, and Deployments that run the production site.

One pattern this organization could follow is to partition the Kubernetes cluster into two namespaces: development and production.
Örnek
Yeni bir namespace yaratmak için şöyle yaparız
kubectl create namespace yb-demo
create secret 
Örnek
Şöyle yaparız
kubectl create secret generic test --from-file=appsettings.json --dry-run -oyaml |
kubectl apply -f -
create serviceaccount
Açıklaması şöyle.
The command to create a ServiceAccount. The created secret holds the public CA of the API server and a signed JSON Web Token (JWT)
ServiceAccount ismi testuser olan girdi yaratmak için şöyle yaparız
kubectl create serviceaccount testuser
describe podname
İsmi belirtilen pod hakkında bilgi almak içindir.
Örnek
İsmi test-pod olan pod hakkında bilgi almak için şöyle yaparız
kubectl describe test-pod
exec -it podname
Interactive mod'a geçip shell açmak içindir.
Örnek
İsmi test-pod olan pod'a shell açmak için şöyle yaparız
kubectl exec -it test-pod -- sh
Örnek
namespace belirterek interactive shell açmak istersek şöyle yaparız. -n ile namespace belirtilir.
kubectl exec -n yb-demo -it yb-tserver-0 /bin/bash
get all
Tüm servis'leri listeler
-A seçeneği
Örnek
Yedekleme için şöyle yaparız
kubectl get all -A -o yaml > backup.yaml
get hostendpoint
Örnek
Şöyle yaparız
#!/bin/sh
kubectl get hostendpoint $NODE_NAME
if [ $? -eq 0 ]; then
  echo "Found hep for node $NODE_NAME"
  ...
fi
get nodes
get nodes yazısına taşıdım

get serviceaccount
Açıklaması şöyle.
The command to display the yaml revealing the associated secret:
Örnek
şöyle yaparız
kubectl get serviceaccount testuser -o yaml
get services
get services yazısına taşıdım

get pods
get pods yazısına taşıdım

get secret + serviceaccount
Açıklaması şöyle.
The command to obtain the encoded token data
Örnek
Şöyle yaparız
kubectl get secret testuser-token-mgtnp -o yaml
Örnek
Şöyle yaparız
kubctl get secret websitesslcert-staging -o yaml 

apiVersion: v1
data:
  tls.crt: REDACTED=
  tls.key: REDACTED=
kind: Secret
metadata:
  annotations:
    cert-manager.io/alt-names: mysite.com
    cert-manager.io/certificate-name: websitesslcert-staging
    cert-manager.io/common-name: mysite.com
    cert-manager.io/ip-sans: ""
    cert-manager.io/issuer-group: cert-manager.io
    cert-manager.io/issuer-kind: ClusterIssuer
    cert-manager.io/issuer-name: letsencrypt-staging
    cert-manager.io/uri-sans: ""
  creationTimestamp: "2021-10-17T00:00:00Z"
  name: websitesslcert-staging
  namespace: default
  resourceVersion: "123456"
  uid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
type: kubernetes.io/tls
get secrets
Açıklaması şöyle.
The command to display available tokens
Şöyle yaparız
kubectl get secrets
scale seçeneği
scale seçeneği yazısına taşıdım