第七题:Service:
题目:使用front-end-service服务,将名为front-end的pod,用NodePort/ClusterIP的方式发布出来
解题思路:
本题考的是Service的暴露方式:
kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name]
[--name=name] [--external-ip=external-ip-of-service] [--type=type] [options]
具体可参考:https://kubernetes.io/docs/reference/kubectl/cheatsheet/
解题步骤:
- 步骤1 :初始化一个pod:
sudo kubectl run nginx-service --image=nginx --generator=run-pod/v1 --dry-run -o yaml > nginx-service.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx-service
name: nginx-service
namespace: ns-ehj
spec:
containers:
- image: nginx
name: nginx-service
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
初始化Pod
- 步骤2: 将该pod暴露出去:
sudo kubectl expose pod nginx-service --port=80 --target-port=8080 --type="NodePort" -n ns-ehj
暴露为NodePort
网友评论