dcube文档_CKA报名详细流程,附优惠码,立减800元人民币

优惠码:

BUNDLE60,具体报名细节,请往下面看

上次考题

Set configuration context $ kubectl config use-context k8s;

Create a deployment as follows;

Name: nginx-dns;

Exposed via a service: nginx-dns;

Ensure that the service & pod are accessible via their respective DNS records;

The container(s) within any pod(s) running as a part of this deployment should use the nginx image;

Next,use the utiliity nslookup to look up the DNS records of the service & pod and write the output to /opt/service.dns and /opt/pod.dns respectively;

Ensure you use the busybox:1.28 image (or earliser) for any testing, an the latest release has an unpstream bug which impacts the use of nslookup;

分析题目

先设置上下文:kubectl config use-context k8s;

按照以下条件创建deployment:

名称:nginx-dns;

暴露service:nginx-dns;

确保可以通过各自的DNS记录访问Service和Pod;

运行的任何Pod中的容器应使用nginx镜像;

接下来,使用nslookup查找service和pod的DNS记录,并将输出分别写入/opt/service.dns和/opt/pod.dns;

确保使用busybox:1.28镜像(或更早的版本)进行测试,最新版本具有unpstream错误,这会影响nslookup的使用;

答案

创建名为nginx-dns的deployment,和一个service,端口80

kubectl run nginx-dns --expose=true --port=80 --image=nginx

利用:kubectl get pods - o wide获取pod的IP:192.168.155.100

启动一个可以运行 nslookup的busybox pod:

kubectl run busybox -it --rm --generator=run-pod/v1 --image=busybox:1.28  sh

执行:

nslookup nginx-dns

nslookup 192.168.155.100

最终的结果,service的dns保存在/opt/service.dns;pod的dns保存在/opt/pod.dns

/ # mkdir opt

/ # nslookup nginx-dns > /opt/service.dns

/ # cat /opt/service.dns

Server:    10.96.0.10

Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      nginx-dns

Address 1: 10.99.28.72 nginx-dns.default.svc.cluster.local

/ # nslookup 192.168.155.100 > /opt/pod.dns

/ # cat /opt/pod.dns

Server:    10.96.0.10

Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      192.168.155.100

Address 1: 192.168.155.100 192-168-155-100.nginx-dns.default.svc.cluster.local

/ #

解析

官网中Pod与Service的DNS解析说明文档:

https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/

Service A 记录

Service(headless Service 除外)将被分配一个 DNS A 记录,格式为 my-svc.my-namespace.svc.cluster-domain.example。该 DNS 记录解析到 Service 的 ClusterIP。

Headless Service(ClusterIP为None)也将被分配一个 DNS A 记录,格式为 my-svc.my-namespace.svc.cluster-domain.example。该 DNS 记录解析到 Service 所选中的一组 Pod 的 IP 地址的集合。

Service SRV 记录

Service(含 headless Service)的命名端口(有 name 的端口)将被分配一个 SRV 记录,其格式为 _my-port-name._my-port-protocol.my-svc.my-namespace.svc.cluster-domain.example:

对于一个普通 Service(非 headless Service),该 SRV 记录解析到其端口号和域名 my-svc.my-namespace.svc.cluster-domain.example

对于一个 Headless Service,该 SRV 记录解析到多个结果:每一个结果都对应该 Service 的一个后端 Pod,包含其端口号和 Pod 的域名 auto-generated-pod-name.my-svc.my-namespace.svc.cluster-domain.example

Pod A 记录

Pod 会以 {podIIP}.my-namespace.pod.cluster.local这种形式被指派一个 DNS A 记录。

例如,default Namespace 具有 DNS 名字cluster.local,在该 Namespace 中一个 IP 为 1.2.3.4 的 Pod 将具有一个条目:1-2-3-4.default.pod.cluster.local。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值