第一步,编写首次部署所需的yaml文件,包括三块:命名空间定义、服务定义、部署定义,nginx的镜像版本为 1.16.1
内容如下:
apiVersion: v1
kind: Namespace
metadata:
name: load-balance
---
kind: Service
apiVersion: v1
metadata:
labels:
app: nginx-1161
name: nginx-1161
namespace: load-balance
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30012
selector:
app: nginx-1161
---
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
app: nginx-1161
name: nginx-1161
namespace: load-balance
spec:
replicas: 3
selector:
matchLabels:
app: nginx-1161
template:
metadata:
labels:
app: nginx-1161
spec:
containers:
- name: nginx
image: nginx:1.16.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
protocol: TCP
# 执行创建
$ kubectl apply -f ./nginx-deployment.yaml
namespace/load-balance created
service/nginx-