Skip to content

Instantly share code, notes, and snippets.

@musfirotus
Last active September 24, 2020 10:09
Show Gist options
  • Save musfirotus/c19b757cc06b6bb7e67ecb597e27815a to your computer and use it in GitHub Desktop.
Save musfirotus/c19b757cc06b6bb7e67ecb597e27815a to your computer and use it in GitHub Desktop.
My Kubernetes Cheatsheet Part 2

Kubernetes Part 2


Annotation

Annotation hampir sama dengan label

Bedanya, di annotation bisa menggunakan spasi

Tapi tidak bisa dilakukan filtering

Bisa sampai 256kb

  • Contoh membuat pod dengan annotation (nginx)
     apiVersion: v1
     kind: Pod
     metadata:
       name: nginx-with-annotation
       labels:
     	team: fe
     	version: 1.4.1
     	environment: qa
       annotations:
     	description: Ini adalah percobaan pod dengan annotation
     	something: Apapun itu yaaa...
     spec:
       containers:
     	- name: nginx
     	  image: nginx
     	  ports:
     		- containerPort: 80
    • Terminal
       kubectl create -f <namafile>.yaml
    • Output
       pod/<namapod> created
  • Melihat detail annotation di sebuah pod
     kubectl describe pod nginx-with-annotation
  • Menambah dan mengubah annotation pod
    • Menambah
      • Terminal
         kubectl annotate pod <namapod> <key>=<value>
    • Mengubah
      • Terminal
         kubectl annotate pod <namapod> <key>=<value> --overwrite
    • Output
       pod/<namapod> annotated
    • Cek penambahan dan mengubahan
       kubectl descrive pod <namapod>

Namespace


General

  • Melihat Semua Namespace
    • Terminal
       kubectl get namespaces
      atau
       kubectl get namespace
      atau
       kubectl get ns
    • Output Example
       NAME              STATUS   AGE
       default           Active   14h
       kube-node-lease   Active   14h
       kube-public       Active   14h
       kube-system       Active   14h
  • Melihat namespace tertentu
    • Terminal
       kubectl get pod --namespace <namanamespace>
      atau
       kubectl get pod -n <namanamespace>
  • Menghapus namespace
    • Terminal
       kubectl delete namespace <namanamespace>
    • Output
       namespace "<namanamespace>" deleted

Membuat Namespace

  • Configuration file
     apiVersion: v1
     kind: Namespace
     metadata:
     	name: product
  • Generate file
    • Terminal
      • Di default namespace
         kubectl create -f <namafilenamespace>.yaml
      • Di namespace lain
         kubectl create -f <namafilenamespace>.yaml -n <namanamespace>
    • Output
       namespace/<namanamespace> created
  • Cek pod
    • Terminal
       kubectl get pod -n <namanamespace>
    • Output
       NAME          READY   STATUS    RESTARTS   AGE
       nginx-label   1/1     Running   0          121m

Probe (Pengecekan)


Jenis

  • Liveness Probe
     apiVersion: v1
     kind: Pod
     metadata:
       name: pod-name
       labels:
     	label-key1: label-value1
       annotations:
     	annotation-key1: annotation-value
     	annotation-key2: veri long annotation value, bla bla bla bla bla bla
     spec:
       containers:
     	- name: container-name
     	  image: image-name
     	  ports:
     		- containerPort: 80
     	  livenessProbe:
     		httpGet:
     		  path: /health
     		  port: 80
     		initialDelaySeconds: 0
     		periodSeconds: 10
     		timeoutSeconds: 1
     		successThreshold: 1
     		failureThreshold: 3
  • Readiness Probe
     readinessProbe:
     	httpGet:
     		path: /
     		port: 80
     	initialDelaySeconds: 0
     	periodSeconds: 10
     	timeoutSeconds: 1
     	successThreshold: 1
     	failureThreshold: 3
  • Startup Probe
     startupProbe:
     	httpGet:
     		path: / 
     		port: 80
     	initialDelaySeconds: 0
     	periodSeconds: 10
     	timeoutSeconds: 1
     	successThreshold: 1
     	failureThreshold: 3
  • Generate File
    • Terminal
       kubectl create -f <namafile>.yaml
    • Output
       pod/<namapod> created
  • Uji coba
    • Terminal
       kubectl port-forward <namapod> 8080:80
    • Output
       Forwarding from 127.0.0.1:8080 -> 80
       Forwarding from [::1]:8080 -> 80
       Handling connection for 8080
       Handling connection for 8080
    • Tanda jika ada handling dari probe
      • Terminal
         kubectl get pod
      • Output
         NAME                      READY   STATUS             RESTARTS   AGE
         nginx-with-probe          0/1     CrashLoopBackOff   9          17m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment