Task
重新配置 spline-reticulator namespace 中現有的 front-end Deployment,以公開現有容器 nginx 的端口 80/tcp
創建一個名為 front-end-svc 的新 Service ,以公開容器端口 80/tcp
配置新的 Service ,以通過 NodePort 公開各個 Pod
解析:
標準的、將集群內服務暴露給外部訪問的流程??:先在 Deployment 中定義容器端口,再創建一個 NodePort 類型的 Service 來暴露這些端口,并讓 Kubernetes 為它在每個節點上分配一個外部可訪問的端口。
基礎:
Action:
1、修改front-end deployment
kubectl -n spline-reticulator edit deployment front-end
pec:
containers:
- image: vicuu/nginx:hello
imagePullPolicy: IfNotPresent
name: nginx #找到此位置
**ports: #新增這 3 行 - containerPort: 80
protocol: TCP**
2、設置service的NodePort類型,暴露80端口
kubectl -n spline-reticulator expose deployment front-end --type=NodePort --port=80 --target-port=80 --name=front-end-svc
3、檢查效果
kubectl -n spline-reticulator get svc front-end-svc -o wide
curl 10.109.100.207:80
exit