Introduction to Kubernetes
Frank Heilmann
Platform Architect and Freelance Instructor
kubectl: คำสั่งหลักสำหรับโต้ตอบกับ Kubernetes objectspod, service ฯลฯ$$
รูปแบบการใช้งานทั่วไป:
kubectl create -f <Manifest.yml>: สร้าง object ใหม่ โดย
-f ย่อมาจาก "filename"kubectl apply -f <Manifest.yml>: สร้าง object ใหม่ &
เปลี่ยนสถานะของ objectkubectl get <object>:
ดูภาพรวม object ที่ deploy บน Kuberneteskubectl describe <object>: ดูข้อมูลเชิงลึกของ object$$
ดูความช่วยเหลือเพิ่มเติมได้ผ่าน command line option --help
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
แอปพลิเคชัน Stateless:
เมื่อหยุดทำงาน replica ใหม่ของแอป stateless จะถูกสร้างขึ้นและเริ่มทำงานต่อทันที
apiVersion และ kindmetadata และ specspec กำหนดจำนวน replicas, selector และ templateselector ในภายหลังtemplate อธิบายรายละเอียดการสร้าง pod ใน
DeploymentapiVersion: 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>
kubectl apply -f <manifest.yml> เพื่อสร้าง pod และ
นำการเปลี่ยนแปลงไปใช้Introduction to Kubernetes