K8S集群可用性验证 ¶
部署 nginx 服务 ¶
1. 编写资源文件清单
cat > nginx.yaml << "EOF"
---
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-web
spec:
replicas: 2
selector:
name: nginx
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.19.6
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service-nodeport
spec:
ports:
- port: 80
targetPort: 80
nodePort: 30001
protocol: TCP
type: NodePort
selector:
name: nginx
EOF
2. 创建资源
kubectl apply -f nginx.yaml
3. 查看 pod 是否成功创建
kubectl get pods -o wide
4. 查看 svc 信息
kubectl get svc