deployment
定義 deployment 配置文件,命名為:nginx-deployment.yaml
apiVersion: apps/v1 # 1.9.0 之前的版本使用 apps/v1beta2,可通過(guò)命令 kubectl api-versions 查看
kind: Deployment #指定創(chuàng)建資源的角色/類型
metadata: #資源的元數(shù)據(jù)/屬性
name: nginx-deployment #資源的名字,在同一個(gè)namespace中必須唯一
spec:
replicas: 2 #副本數(shù)量2
selector: #定義標(biāo)簽選擇器
matchLabels:
app: web-server
template: #這里Pod的定義
metadata:
labels: #Pod的label
app: web-server
spec: # 指定該資源的內(nèi)容
containers:
- name: nginx #容器的名字
image: nginx:1.12.1 #容器的鏡像地址
ports:
- containerPort: 80 #容器對(duì)外的端口
pod
定義 pod 配置文件,命名為 redis-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-redis
labels:
name: redis
spec:
containers:
- name: pod-redis
image: docker.io/redis
ports:
- containerPort: 80 #容器對(duì)外的端口
service
定義 service 配置文件,命名為 httpd-svc.yaml
apiVersion: v1
kind: Service # 指明資源類型是 service
metadata:
name: httpd-svc # service 的名字是 httpd-svc
labels:
name: httpd-svc
spec:
ports: # 將 service 8080 端口映射到 pod 的 80 端口,使用 TCP 協(xié)議
- port: 8080
targetPort: 80
protocol: TCP
selector:
run: httpd # 指明哪些 label 的 pod 作為 service 的后端