题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
Create a NodePort service named app-service-cka (with below specification) to expose the nginx-app-cka deployment in the nginx-app-space namespace.
- port & target port 80
- protocol TCP
- node port 31000
创建一个名为app-service-cka
的NodePort服务(按照下面的规范),以在nginx-app-space
命名空间中公开nginx-app-cka
部署。
端口和目标端口80
- TCP协议
- 节点接口31000
解题思路
- 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 根据题目的要求编写资服务类型源清单,内容如下:
apiVersion: v1 kind: Service metadata: creationTimestamp: null labels: app: nginx-app-cka name: app-service-cka namespace: nginx-app-space spec: ports: - port: 80 protocol: TCP targetPort: 80 nodePort: 31000 selector: app: nginx-app-cka type: NodePort status: loadBalancer: {}
- 提交资源清单
controlplane $ k apply -f app-service-cka.yaml service/app-service-cka created
- 检查svc状态
controlplane $ k get svc -n nginx-app-space NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE app-service-cka NodePort 10.109.171.243 <none> 80:31000/TCP 13s
题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
Create a deployment named my-web-app-deployment using the Docker image wordpress with 2 replicas. Then, expose the my-web-app-deployment as a service named my-web-app-service , making it accessible on port 30770 on the nodes of the cluster.
使用Docker镜像wordpress创建一个名为my-web-app-deployment
的部署,其中包含两个副本。然后,将my-web-app-deployment
作为一个名为my-web-app-service
的服务公开,使其可以在集群节点的30770
端口上访问。
解题思路
- 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 根据题目的要求,先创建一个名为
my-web-app-deployment
的deploy。
controlplane $ k create deployment my-web-app-deployment --image wordpress --replicas 2 --port 80 deployment.apps/my-web-app-deployment created
- 根据题目要求,创建一个名为
my-web-app-service
的SVC,类型为nodePort。
apiVersion: v1 kind: Service metadata: creationTimestamp: null labels: app: my-web-app-deployment name: my-web-app-service spec: ports: - port: 80 protocol: TCP targetPort: 80 nodePort: 30770 selector: app: my-web-app-deployment type: NodePort status: loadBalancer: {}
- 提交svc资源清单
controlplane $ k apply -f my-web-app-service.yaml service/my-web-app-service created