Kubernetes for Beginner
Gazandi Cahyadarma
Is not
Manajemen Server
Old Deployment
= (Sistem Masak Ayam
Goreng)
= =
# Machine
FROM node:12.16.2-alpine Docker Image
(Sistem Masak Ayam
# SOP Goreng)
RUN mkdir -p /app
WORKDIR /app
# Ingredient
COPY . /app
RUN npm install
#seasoning
ENV HOST 0.0.0.0
ENV PORT 7777
# Recipe
EXPOSE 7777
CMD ["npm", "start"]
# Machine
FROM alpine:3.6 Docker Image
(Sistem Masak Kentang
# SOP Goreng)
RUN mkdir -p /app
WORKDIR /app
# Ingredient and seasoning
COPY . /app
ENV HOST 0.0.0.0
ENV PORT 1111
# Recipe
RUN make build
EXPOSE 1111
CMD ["./api"]
manajemen server kubernetes = manajemen franchise restoran
Training
Trainees
Manager
serve
Sarana Training karyawan
Docker Push to Registry
docker build -t $(IMAGE):$(VERSION) -f ./Dockerfile .
(Sarana Training
docker push $(IMAGE):$(VERSION);
karyawan)
Trainees
Training
Trainer / manager
Deployment
serve
Request
Pod
Deployment yml (Employee Management) Manager
apiVersion: apps/v1 spec:
kind: Deployment containers:
metadata: - name: mask-web
Trainee name: "mask-web-production"
labels:
image: '{{.variable.IMAGE}}'
ports:
project: mask - containerPort: 7777
service: web command:
env: production - npm
spec: args:
replicas: 1 - start
selector: livenessProbe:
matchLabels: httpGet:
project: mask path: /healthz
service: web port: 7777
env: production initialDelaySeconds: 2000
template: timeoutSeconds: 1
metadata: readinessProbe:
annotations: httpGet:
prometheus.io/scrape: "true" path: /healthz
prometheus.io/port: "7777" port: 7777
release: '{{.variable.VERSION}}' timeoutSeconds: 1
labels: resources:
project: mask limits:
service: web memory: 400Mi
Pod release: '{{.variable.VERSION}}'
env: production
cpu: 0.3
requests:
memory: 200Mi
cpu: 0.1
Containers -> tim Masak Ayam
Name: job title (Ayam Engineer) Deployment
Image : Sarana training yang mana (Training)
Command and args : job desc masak ayam
Ports : letak, kitchen
Deployment yml (Employee Management) Manager
apiVersion: apps/v1 spec:
kind: Deployment containers:
metadata: - name: mask-web
Trainee name: "mask-web-production"
labels:
image: '{{.variable.IMAGE}}'
ports:
project: mask - containerPort: 7777
service: web command:
env: production - npm
spec: args:
replicas: 1 - start
selector: livenessProbe:
matchLabels: httpGet:
project: mask path: /healthz
service: web port: 7777
env: production initialDelaySeconds: 2000
template: timeoutSeconds: 1
metadata: readinessProbe:
annotations: httpGet:
prometheus.io/scrape: "true" path: /healthz
prometheus.io/port: "7777" port: 7777
release: timeoutSeconds: 1
'{{.variable.VERSION}}' resources:
labels: limits:
project: mask memory: 400Mi
Pod service: web
release:
cpu: 0.3
requests:
'{{.variable.VERSION}}' memory: 200Mi
env: production cpu: 0.1
Self
Healing
Liveness Probe : Absensi
(Menggantikan Deployment
karyawan shift) Readiness Probe : Well prepared untuk serve
customer
httpGet path and port: letak dan cara tahu
initialDelay&timeout : Batas waktu
Deployment yml (Employee Management) Manager
apiVersion: apps/v1 spec:
kind: Deployment containers:
metadata: - name: mask-web
Trainee name: "mask-web-production"
labels:
image: '{{.variable.IMAGE}}'
ports:
project: mask - containerPort: 7777
service: web command:
env: production - npm
spec: args:
replicas: 1 - start
selector: livenessProbe:
matchLabels: httpGet:
project: mask path: /healthz
service: web port: 7777
env: production initialDelaySeconds: 2000
template: timeoutSeconds: 1
metadata: readinessProbe:
annotations: httpGet:
prometheus.io/scrape: "true" path: /healthz
prometheus.io/port: "7777" port: 7777
release: timeoutSeconds: 1
'{{.variable.VERSION}}' resources:
labels: limits:
project: mask memory: 400Mi
Pod service: web
release:
cpu: 0.3
requests:
'{{.variable.VERSION}}' memory: 200Mi
env: production cpu: 0.1
Resources
Requests: Minimum kinerja karyawan ( Deployment
min di kantor 8 jam )
Limit: Maksimum kinerja karyawan ( max
jam kerja 12 jam)
Deployment yml (Employee Management) Manager
apiVersion: apps/v1 spec:
kind: Deployment containers:
metadata: - name: mask-web
Trainee name: "mask-web-production"
labels:
image: '{{.variable.IMAGE}}'
ports:
project: mask - containerPort: 7777
service: web command:
env: production - npm
spec: args:
replicas: 1 - start
selector: livenessProbe:
matchLabels: httpGet:
project: mask path: /healthz
service: web port: 7777
env: production initialDelaySeconds: 2000
template: timeoutSeconds: 1
metadata: readinessProbe:
annotations: httpGet:
prometheus.io/scrape: "true" path: /healthz
prometheus.io/port: "7777" port: 7777
release: timeoutSeconds: 1
'{{.variable.VERSION}}' resources:
labels: limits:
project: mask memory: 400Mi
Pod service: web
release:
cpu: 0.3
requests:
'{{.variable.VERSION}}' memory: 200Mi
env: production cpu: 0.1
Replicas: jumlah tim
Labels : nama toko Deployment
Selector : nama toko
(Labels dan selector harus sama)
Trainees
Melayani di luar
kapasitas kinerja
Trainees
Menambahkan
banyak orang
(optimal)
Trainees
Terlalu banyak
pekerja
Trainees
Pelayanan
Optimal
Trainees
Scale up (tambahkan jumlah/kapasitas server)
kubectl scale deployment my-app --replicas 3
Pelayanan or
Optimal
Trainees
Scale down (kurangi jumlah/kapasitas server)
kubectl scale deployment my-app --replicas 1
Trainees HPA.yml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: mask-web-production
namespace: default
labels:
project: mask
service: web
env: production
spec:
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: mask-web-production
Pelayanan minReplicas: 1
or maxReplicas:3
Optimal targetCPUUtilizationPercentage: 80%
Trainees
scaleTargetRef: target scale
minReplicas: minimum karyawan
maxReplicas: maksimum karyawan
targetCPUUtilizationPercentage: kondisi
penambahan dan pengurangan
Service.yml
apiVersion: v1
kind: Service
metadata:
Train labels:
Trainees
ees project: mask
service: web
env: production
name:
mask-web-production
namespace: default
spec:
selector:
project: mask
service: web
env: production
Pembagian tugas ports:
biar sama rata - protocol: TCP
(Load Management) port: 7777
type: NodePort
Ports: Lokasi penjualan
Labels : nama toko
Selector : nama toko Pod
(labels dan selector harus sesuai
Dengan deployment.yml)
Trainees
Melayani karena
ada sarana untuk
menjual
Trainees
Melayani karena
ada sarana untuk
menjual
Request Ingress.yml
Pod
Ingress.yml
apiVersion: v1/beta1
kind: Ingress
metadata:
labels:
project: mask
env: production Service Ports: Lokasi ambil
name: mask-ingress
namespace: default makanan
spec: serviceName: Nama toko
rules:
- host: mask.com (order-makanan-dari-gojek)
Rules: ngarahin dari aplikasi
http: gofood/grabfood ke hape penjual
paths:
- backend:
serviceName: mask_service (manager Adrian)
servicePort: 9999 (pojok)
path: /
- host: maskeran.com (order-makanan-dari-grabfood)
http:
paths:
- backend:
serviceName: maskeran_service (manager Gazan)
servicePort: 8888 (depan gerbang
path: /
Sesi Intip Kubernetes dari GCP
Mau belajar lagi ?
Ada mentorship Gratis di Developer Circle
Jakarta kok!