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

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
可观测可视化 Grafana 版,10个用户账号 1个月
简介: 【CKA模拟题】不可不知:NodePort操作全攻略!

题干

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
相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务&nbsp;ACK 容器服务&nbsp;Kubernetes&nbsp;版(简称&nbsp;ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情:&nbsp;https://www.aliyun.com/product/kubernetes
目录
相关文章
|
1月前
【CKA模拟题】Ingress新手必看,全面了解Ingress的基础操作
【CKA模拟题】Ingress新手必看,全面了解Ingress的基础操作
111 1
|
1月前
|
存储 Kubernetes 容器
【CKA模拟题】一文教你如何查看并优雅地排序SVC资源
【CKA模拟题】一文教你如何查看并优雅地排序SVC资源
81 1
|
1月前
|
运维 Kubernetes 监控
CKA备考攻略:掌握Pod日志收集,事半功倍的秘诀!
CKA备考攻略:掌握Pod日志收集,事半功倍的秘诀!
29 0
CKA备考攻略:掌握Pod日志收集,事半功倍的秘诀!
|
1月前
|
Kubernetes 安全 调度
提升CKA认证成功率,CKA真题中的节点维护全攻略!
提升CKA认证成功率,CKA真题中的节点维护全攻略!
29 0
|
1月前
|
Kubernetes 应用服务中间件 nginx
【CKA模拟题】别再犯难!一文教你用两种方式快速创建Pod!
【CKA模拟题】别再犯难!一文教你用两种方式快速创建Pod!
25 1
|
1月前
|
存储 运维 Kubernetes
PV与PVC知多少?解锁CKA认证考点攻略!
PV与PVC知多少?解锁CKA认证考点攻略!
44 0
|
8月前
|
Kubernetes API 调度
21道题帮你轻松拿捏 Kubernetes 面试
21道题帮你轻松拿捏 Kubernetes 面试
|
7月前
|
Kubernetes 负载均衡 应用服务中间件
【K8S系列】第十三讲:Ingress详解
【K8S系列】第十三讲:Ingress详解
764 0
|
8月前
|
Kubernetes 调度 Perl
Kubernetes CKA 模拟题解析【2022最新版】(连载002)
Kubernetes CKA 模拟题解析【2022最新版】(连载002)
|
1月前
|
存储 应用服务中间件 nginx
【CKA模拟题】StorageClass实战案例分析
【4月更文挑战第5天】【CKA模拟题】StorageClass实战案例分析
35 13