【CKA模拟题】不可不知:NodePort操作全攻略!

本文介绍了如何在Kubernetes环境中,使用`kubectl`配置管理员权限,创建NodePort服务,包括app-service-cka(基于Nginx-app-ckadeployment)和my-web-app-service(基于WordPressDocker镜像的Deployment)。分别展示了设置服务端口、选择器和提交资源清单的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

题干

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

解题思路

  1. 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
  1. 根据题目的要求编写资服务类型源清单,内容如下:
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: {}
  1. 提交资源清单
controlplane $ k apply  -f app-service-cka.yaml 
service/app-service-cka created
  1. 检查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端口上访问。

解题思路

  1. 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
  1. 根据题目的要求,先创建一个名为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
  1. 根据题目要求,创建一个名为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: {}
  1. 提交svc资源清单
controlplane $ k apply  -f my-web-app-service.yaml
service/my-web-app-service created
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

didiplus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值