Ch19 建立環境
步驟
-
建立以下
nginx-nlb-service-demo.yaml
YAML。使用 Nginx 作為 server-side 應用程式。$ cat ./nginx-nlb-service-demo.yaml
apiVersion: v1
kind: Namespace
metadata:
name: "nginx-demo"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: "nginx-demo-deployment"
namespace: "nginx-demo"
spec:
selector:
matchLabels:
app: "nginx-demo"
replicas: 3
template:
metadata:
labels:
app: "nginx-demo"
role: "backend"
spec:
containers:
- image: nginx:latest
imagePullPolicy: Always
name: "nginx-demo"
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: "service-nginx-demo"
namespace: "nginx-demo"
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: nlb
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: "nginx-demo" -
建立以下
netshoot.yaml
文件作為 client。$ cat ./netshoot.yaml
apiVersion: v1
kind: Pod
metadata:
name: netshoot
spec:
containers:
- name: netshoot
image: nicolaka/netshoot:latest
command:
- sleep
- infinity
imagePullPolicy: IfNotPresent
restartPolicy: Alway -
部署
Deployment
,這邊以 Nginx server 作為 server-side。$ kubectl apply -f ./nginx-nlb-service-demo.yaml
namespace/nginx-demo created
deployment.apps/nginx-demo-deployment created
service/service-nginx-demo created -
部署 Pod
netshoot
。$ kubectl apply -f ./netshoot.yaml
pod/netshoot created