Mendeploy Aplikasi (Stateless) Pertama

Pengantar Kubernetes

Frank Heilmann

Platform Architect and Freelance Instructor

Lebih lanjut tentang "kubectl"

  • kubectl: perintah utama untuk berinteraksi dengan objek Kubernetes
  • Objek misalnya pod, service, dll.

$$

  • Pola penggunaan umum:

    • kubectl create -f <Manifest.yml>: membuat objek baru, -f untuk "filename"
    • kubectl apply -f <Manifest.yml>: membuat objek baru & mengubah state objek
    • kubectl get <object>: ringkasan objek yang dideploy di Kubernetes
    • kubectl describe <object>: info rinci tentang suatu objek

    $$

  • Bantuan rinci tersedia via opsi baris perintah --help

Pengantar Kubernetes

Lebih lanjut tentang Manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 5
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.25.4
        ports:
        - containerPort: 80
  • Ingat: Manifest bersifat deklaratif
  • Biasanya YAML, tapi juga bisa JSON
  • Dua bagian penting:
    • metadata: info penting tentang objek atau resource
    • spec: mendefinisikan spesifikasi atau state yang diinginkan dari objek atau resource
  • Bagian-bagian dapat cukup dalam, tergantung resource yang dideploy
Pengantar Kubernetes

Aplikasi Stateless

  • Aplikasi stateless:

    • Konsep umum
    • Tidak spesifik untuk Kubernetes
    • Tidak menyimpan state internal atau konteks data yang diproses
  • Saat terhenti, replika baru aplikasi stateless dibuat ulang dan mulai berjalan.

  • Contoh:
    • Frontend database yang melakukan query ke backend database
    • Aplikasi pencarian yang melakukan query ke indeks full-text
    • Aplikasi stream data yang mengonversi suhu dari sensor IoT dari °F ke °C
Pengantar Kubernetes

Kubernetes Deployments

  • "Aplikasi stateless" direpresentasikan sebagai "Kubernetes Deployments"
  • Contoh Manifest terdiri dari:
    • apiVersion dan kind
    • metadata dan spec
  • spec mendefinisikan jumlah replicas, selector, dan template
  • Lebih lanjut tentang selector nanti
  • template menjelaskan detail pembuatan pod dalam Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: <deployment name>
  labels:
    app: <a label for the application>
spec:
  replicas: <number of initial replicas>
  selector:
    matchLabels:
      app: <matches the label above>
  template:
    metadata:
      labels:
        app: <label to be given to each pod>
    spec:
      containers:
      - name: <container name>
        image: <the image to be used>
        ports:
        - containerPort: <ports for networking>
Pengantar Kubernetes

Mendeploy ke Cluster Kubernetes

  • kubectl apply -f <manifest.yml> untuk membuat pod dan menerapkan perubahan.
  • Control Plane Kubernetes akan menjadwalkan Deployment ke Node.
    • Lalu, pembuatan Pod dipicu di Node.
  • Pod mendapat pengenal unik namun acak (tidak dapat diprediksi), setiap Pod "setara satu sama lain"
Pengantar Kubernetes

Ayo berlatih!

Pengantar Kubernetes

Preparing Video For Download...