Nhập môn Kubernetes
Frank Heilmann
Platform Architect and Freelance Instructor
kubectl: lệnh chính để làm việc với các đối tượng Kubernetespod, service, v.v.$$
Cách dùng thường gặp:
kubectl create -f <Manifest.yml>: tạo đối tượng mới,
-f là "filename"kubectl apply -f <Manifest.yml>: tạo mới và
áp dụng thay đổi trạng thái đối tượngkubectl get <object>:
xem tổng quan các đối tượng đã triển khaikubectl describe <object>: thông tin chi tiết về một đối tượng$$
Trợ giúp chi tiết qua tùy chọn dòng lệnh --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
Ứng dụng không trạng thái:
Khi bị gián đoạn, một bản sao mới được tạo lại và tiếp tục chạy.
apiVersion và kindmetadata và specspec định nghĩa số replicas, selector, và templateselector sautemplate mô tả chi tiết tạo pod trong
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> để tạo pod và áp dụng thay đổi.Nhập môn Kubernetes