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

本文涉及的产品
注册配置 MSE Nacos/ZooKeeper,118元/月
性能测试 PTS,5000VUM额度
函数计算FC,每月15万CU 3个月
简介: 【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
相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
相关文章
|
9月前
|
Perl 容器
【CKA模拟题】学会使用ReplicaSet和Deployment
【CKA模拟题】学会使用ReplicaSet和Deployment
216 1
|
9月前
【CKA模拟题】Ingress新手必看,全面了解Ingress的基础操作
【CKA模拟题】Ingress新手必看,全面了解Ingress的基础操作
217 1
|
9月前
|
Kubernetes 应用服务中间件 nginx
【CKA模拟题】别再犯难!一文教你用两种方式快速创建Pod!
【CKA模拟题】别再犯难!一文教你用两种方式快速创建Pod!
142 1
|
9月前
|
网络协议 应用服务中间件 nginx
【CKA模拟题】如何用Nslookup轻松检查集群服务名的DNS解析?
【CKA模拟题】如何用Nslookup轻松检查集群服务名的DNS解析?
272 2
|
9月前
|
存储 Kubernetes 容器
【CKA模拟题】一文教你如何查看并优雅地排序SVC资源
【CKA模拟题】一文教你如何查看并优雅地排序SVC资源
146 1
|
9月前
|
C++
C++ 数学函数、头文件及布尔类型详解
C++ 支持数学操作,如`max`和`min`函数找最大值和最小值,以及`&lt;cmath&gt;`库中的`sqrt`、`round`等数学函数。`bool`类型用于布尔逻辑,取值`true`(1)或`false`(0)。布尔表达式结合比较运算符常用于条件判断,例如在`if`语句中检查年龄是否达到投票年龄。在代码示例中,`isCodingFun`和`isFishTasty`变量分别输出1和0。
212 1
|
9月前
|
存储 运维 Kubernetes
PV与PVC知多少?解锁CKA认证考点攻略!
PV与PVC知多少?解锁CKA认证考点攻略!
128 0
|
9月前
|
人工智能 自然语言处理 搜索推荐
微调工程师岗位可能并不存在,但使用 AI 编码工具已经成为刚需
阿里云通义灵码,作为智能编码助手,下载量超130万,引领国内AI编码工具市场。
115877 93
|
9月前
|
存储
【CKA模拟题】案例演示如何创建PVC
【CKA模拟题】案例演示如何创建PVC
139 2
|
9月前
【CKA模拟题】实战案例带你掌握如何创建PV
【CKA模拟题】实战案例带你掌握如何创建PV
157 1