Kubernetes扩展插件 Cluster DNS安装

Kubernetes扩展插件 Cluster DNS安装

 

回到master机器 10.99.0.10

 

skydns配置文件所在目录(本例子使用getting-started-guides目录下的文件)

[root@vultr ~]# find -name *skydns*

./kubernetes/cluster/libvirt-coreos/skydns-rc.yaml

./kubernetes/cluster/libvirt-coreos/skydns-svc.yaml

./kubernetes/cluster/gce/coreos/kube-manifests/addons/dns/skydns-rc.yaml

./kubernetes/cluster/gce/coreos/kube-manifests/addons/dns/skydns-svc.yaml

./kubernetes/cluster/juju/layers/kubernetes/templates/skydns-rc.yml

./kubernetes/cluster/juju/layers/kubernetes/templates/skydns-svc.yml

./kubernetes/docs/getting-started-guides/coreos/azure/addons/skydns-rc.yaml

./kubernetes/docs/getting-started-guides/coreos/azure/addons/skydns-svc.yaml

 

创建一个工作目录

cd ~/kubernetes/docs/getting-started-guides/coreos/azure/addons/

mkdir -p ~/workspace/skydns

cp skydns-* ~/workspace/skydns/

cd ~/workspace/skydns

ls -l

 

修改skydns-rc.yaml 和 skydns-svc.yaml        

 

sed -i "s/replicas: 3/replicas: 1/" skydns-rc.yaml

 

sed -i "s/kube.local/cluster.local/" skydns-rc.yaml

sed -i "s/kube-00/10.99.0.10/" skydns-rc.yaml

 

sed -i "s/localhost/127.0.0.1/" skydns-rc.yaml

sed -i "s/kube.local/cluster.local./" skydns-rc.yaml

 

sed -i "s/kubernetes.default.svc.kube.local/kubernetes.default.svc.cluster.local/" skydns-rc.yaml

 

sed -i "s/10.16.0.3/172.16.66.66/" skydns-svc.yaml

 

 

创建Kubernetes DNS

[root@vultr skydns]#kubectl create -f skydns-rc.yaml

replicationcontroller "kube-dns-v9" created

 

[root@vultr skydns]# kubectl get pod --selector k8s-app=kube-dns --namespace=kube-system

NAME                READY     STATUS    RESTARTS   AGE

kube-dns-v9-hgnfh   4/4       Running   0          16s

 

[root@vultr skydns]# kubectl create -f skydns-svc.yaml

kubectl get service -l k8s-app=kube-dns --namespace=kube-systemservice "kube-dns" created

[root@vultr skydns]# kubectl get service -l k8s-app=kube-dns --namespace=kube-system

NAME       CLUSTER-IP     EXTERNAL-IP   PORT(S)         AGE

kube-dns   172.16.66.66          53/UDP,53/TCP   2s

 

 

kubectl cluster-info

返回结果

Kubernetes master is running at http://localhost:8080

KubeDNS is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kube-dns

 

实际上访问

http://master机器IP:8080/api/v1/namespaces/kube-system/services/kube-dns

可以看到详细信息

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "kube-dns",
    "namespace": "kube-system",
    "selfLink": "/api/v1/namespaces/kube-system/services/kube-dns",
    ... ...

 

 

修改各节点机器上的kubelet配置

vi /etc/sysconfig/kubelet

--cluster-dns=172.16.66.66

--cluster-domain=cluster.local

 

重启节点机器上的kubelet

systemctl restart kubelet

systemctl status -l kubelet

 

创建一个测试pod

echo "  apiVersion: v1

  kind: ReplicationController

  metadata:

      name: tomcat

  spec:

    replicas: 1

    template:

      metadata:

        labels:

          app: tomcat

      spec:

        containers:

          - name: tomcat

            image: tomcat" > tomcat.yaml

 

cat tomcat.yaml

 

kubectl --server=10.99.0.10:8080 create -f tomcat.yaml 

kubectl get pod

 

进入到pod中的第一个容器

kubectl exec tomcat-4d33v -i -t -- bash

查看DNS

cat /etc/resolv.conf

 

search default.svc.cluster.local svc.cluster.local cluster.local

nameserver 172.16.66.66

options ndots:5

 

之前创建的pod DNS未改变,需要删除之后重建

kubectl --server=10.99.0.10:8080 delete -f test-1.yaml 

kubectl --server=10.99.0.10:8080 delete -f test-2.yaml 

kubectl --server=10.99.0.10:8080 delete -f test-3.yaml 

kubectl --server=10.99.0.10:8080 delete -f test-4.yaml 

 

kubectl --server=10.99.0.10:8080 create -f test-1.yaml  

kubectl --server=10.99.0.10:8080 create -f test-2.yaml 

kubectl --server=10.99.0.10:8080 create -f test-3.yaml 

kubectl --server=10.99.0.10:8080 create -f test-4.yaml 

 

kubectl --server=10.99.0.10:8080 get pods

 

进入test-1-cqc6p点的第一个容器查看DNS

kubectl exec test-1-cqc6p -i -t -- bash

cat /etc/resolv.conf

 

search default.svc.cluster.local svc.cluster.local cluster.local

nameserver 172.16.66.66

options ndots:5

 

expose 创建tomcat service

kubectl expose replicationcontroller tomcat --port=8080 --target-port=8099 

 

 

你可能感兴趣的:(Kubernetes)