涅槃を目指す in はてな

人生に迷う様を書きます

Kubernetes The Hard Way On VirtualBox 12日目

Kubernetesを雰囲気で使わないための修行Kubernetes The Hard Way On VirtualBoxの12日目。

Deploying the DNS Cluster Add-on

今回は Kubernetesクラスタ内部にCoreDNSを使った名前解決の仕組みをデプロイします。DNSベースのサービスディスカバリのためです。

The DNS Cluster Add-on

corednsアドオンをデプロイします。

kubectl apply -f https://raw.githubusercontent.com/mmumshad/kubernetes-the-hard-way/master/deployments/coredns.yaml

実行結果

vagrant@master-1:~$ kubectl apply -f https://raw.githubusercontent.com/mmumshad/kubernetes-the-hard-way/master/deployments/coredns.yaml
serviceaccount/coredns created
configmap/coredns created
deployment.apps/coredns created
service/kube-dns created
unable to recognize "https://raw.githubusercontent.com/mmumshad/kubernetes-the-hard-way/master/deployments/coredns.yaml": no matches for kind "ClusterRole" in version "rbac.authorization.k8s.io/v1beta1"
unable to recognize "https://raw.githubusercontent.com/mmumshad/kubernetes-the-hard-way/master/deployments/coredns.yaml": no matches for kind "ClusterRoleBinding" in version "rbac.authorization.k8s.io/v1beta1"

あー、rbac.authorization.k8s.io/v1beta1rbac.authorization.k8s.io/v1になってる問題か!

修正したいので、

wget https://raw.githubusercontent.com/mmumshad/kubernetes-the-hard-way/master/deployments/coredns.yaml

でcoredns.yamlを落としてきて、rbac.authorization.k8s.io/v1beta1rbac.authorization.k8s.io/v1に置換しました。

実行結果

vagrant@master-1:~$ kubectl apply -f coredns.yaml serviceaccount/coredns unchanged
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
configmap/coredns unchanged
deployment.apps/coredns unchanged
service/kube-dns unchanged

OKOK!

kube-dns デプロイメントによって作られたpodを確認できます。

kubectl get pods -l k8s-app=kube-dns -n kube-system

実行結果

vagrant@master-1:~$ kubectl get pods -l k8s-app=kube-dns -n kube-system
NAME                       READY   STATUS    RESTARTS       AGE
coredns-5cccc7b6cc-l2w6g   1/1     Running   2 (2m4s ago)   6m34s
coredns-5cccc7b6cc-nsp28   1/1     Running   2 (2m4s ago)   6m34s

Verification

busybox podを作成ます。公式だと --generator=run-pod/v1 というオプションがついてますが、kubernetes v1.18以降では不要です。

kubectl run busybox --image=busybox:1.28 --command -- sleep 3600

作成されたpodを確認

kubectl get pods -l run=busybox

実行結果

vagrant@master-1:~$ kubectl get pods -l run=busybox
NAME      READY   STATUS    RESTARTS   AGE
busybox   1/1     Running   0          23s

作成したpodの名前解決が出来るか、kubernetesサービスにDNS Lookupをしてみましょう

kubectl exec -ti busybox -- nslookup kubernetes

実行結果

vagrant@master-1:~$ kubectl exec -ti busybox -- nslookup kubernetes
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local

出来ているようですね!

今回はここまで! お読み頂き有難うございました!