Skip to content

antony@notes:~/rancher$ cat "Pod-使用-K8S-外部-DNS-Server-Rancher-對-RKE2-Snapshot-的前置設定.md"

Pod 使用 K8S 外部 DNS Server & Rancher 對 RKE2 Snapshot 的前置設定

2023-07-27· rancher ·系統工程

Preface

本篇文章會介紹,

  1. 如何讓 Pod 使用 K8S 外部的 DNS Server
  2. Rancher 對 RKE2 Snapshot 的前置設定

可以透過點擊展開以下目錄,選擇想看的內容,跳轉至特定章節

:::warning

:::spoiler 文章目錄

[TOC]

:::

Pod 使用 K8S 外部 DNS Server

Sample: Pod Yaml File

$ echo 'apiVersion: v1
kind: Pod
metadata:
  name: test
  namespace: default
spec:
  containers:
  - image: quay.io/hahappyman/alpine
    command:
      - sleep
      - "360000"
    imagePullPolicy: IfNotPresent
    name: test
  restartPolicy: Always
  dnsConfig:
    nameservers:
      - 192.168.11.97' > pod.yaml
  • DNSConfig 可以讓使用者直接輸入 DNS 相關的參數,該參數會擴充該 Pod原本的 DNS 設定檔案。
    • dnsConfig.nameservers,指定 K8S 外部的 DNS Server IP Address

建立 Pod

$ kubectl apply -f pod.yaml

檢視在 Pod 中,新加入的 DNS Server

$ kubectl exec test -- cat /etc/resolv.conf

螢幕輸出 :

search default.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.43.0.10
nameserver 192.168.11.97

在 nameserver 的欄位可以看到多了一筆 192.168.11.97

測試名稱解析

$ kubectl exec test -- ping -c 1 rancher.example.com

螢幕輸出 :

PING rancher.example.com (192.168.11.11): 56 data bytes
64 bytes from 192.168.11.11: seq=0 ttl=63 time=0.830 ms

--- rancher.example.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.830/0.830/0.830 ms

可以看到成功將 rancher.example.com 解析成 192.168.11.11


Rancher 對 RKE2 Snapshot 的前置設定

  • 使用 Rancher 生成的 RKE2 Cluste,需要把 rke2 命令複製到/usr/local/bin/
  • 需要在叢集中的每一台 Node 上都執行以下命令
$ sudo cp /opt/rke2/bin/* /usr/local/bin/