二进制安装kubernetes v1.11.2 (第十六章 coredns插件部署)

coredns插件部署

16.1 下载和分发二进制文件,参考 第三章

# 解压二进制文件
[root@k8s-m1 ~]# cd ~/k8s/v1.11.2/kubernetes/
[root@k8s-m1 kubernetes]# tar zxvf kubernetes-src.tar.gz
[root@k8s-m1 ~]# cd ~/k8s/v1.11.2/kubernetes/cluster/addons/dns/coredns

# 复制一份配置文件,然后修改3个地方
[root@k8s-m1 coredns]# cp coredns.yaml.base coredns.yaml
[root@k8s-m1 coredns]# diff coredns.yaml.base coredns.yaml
61c61
<         kubernetes __PILLAR__DNS__DOMAIN__ in-addr.arpa ip6.arpa {
---
>         kubernetes cluster.local. in-addr.arpa ip6.arpa {
109c109
<         image: k8s.gcr.io/coredns:1.1.3
---
>         image: registry.cn-shenzhen.aliyuncs.com/acs/coredns:1.1.3
174c174
<   clusterIP: __PILLAR__DNS__SERVER__
---
>   clusterIP: 10.254.0.2

# 使配置文件生效
[root@k8s-m1 coredns]# kubectl apply -f coredns.yaml

16.2  检查 coredns 功能

[root@k8s-m1 kubernetes]# kubectl get all -n kube-system
NAME                           READY     STATUS    RESTARTS   AGE
pod/coredns-55877fc9fb-bw6w5   1/1       Running   4          11m

NAME               TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
service/kube-dns   ClusterIP   10.254.0.2   <none>        53/UDP,53/TCP   1h

NAME                      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/coredns   1         1         1            1           1h

NAME                                 DESIRED   CURRENT   READY     AGE
replicaset.apps/coredns-55877fc9fb   1         1         1         11m
replicaset.apps/coredns-77cd44d8df   0         0         0         1h

16.3 新建一个 deployment

$ cat > my-nginx.yaml <<EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-nginx
spec:
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
EOF
$ kubectl create -f my-nginx.yaml

expose 该 deployment 生成 my-nginx 服务:

[root@k8s-m1 yaml]# kubectl expose deploy my-nginx
service/my-nginx exposed
[root@k8s-m1 yaml]# kubectl get services --all-namespaces |grep my-nginx
default       my-nginx                 ClusterIP   10.254.118.166   <none>        80/TCP          1m

 16.4 创建一个 pod,然后进入这个 pod ,ping svc 服务的名字

# 创建新的 pod
[root@k8s-m1 yaml]# cat pod-nginx.yaml apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80

# ping

[root@k8s-m2 ~]# kubectl exec nginx -it bash
root@nginx:/# ping my-nginx
PING my-nginx.default.svc.cluster.local (10.254.118.166): 48 data bytes
56 bytes from 10.254.118.166: icmp_seq=0 ttl=64 time=0.078 ms
^C--- my-nginx.default.svc.cluster.local ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.078/0.078/0.078/0.000 ms

root@nginx:/# ping kubernetes
PING kubernetes.default.svc.cluster.local (10.254.0.1): 48 data bytes
56 bytes from 10.254.0.1: icmp_seq=0 ttl=64 time=0.120 ms
56 bytes from 10.254.0.1: icmp_seq=1 ttl=64 time=0.149 ms
^C--- kubernetes.default.svc.cluster.local ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.120/0.135/0.149/0.000 ms

 

 

16.5 给 Service 绑定 IP

[root@k8s-m1 yaml]# cat gu.ding.ip_services.yaml 
apiVersion: v1 
kind: Service 
metadata: 
  name: gudingip-nginx
spec: 
  clusterIP: 10.254.100.100
  ports: 
    - port: 8000
      targetPort: 80 
      protocol: TCP
      nodePort: 8602
  type: NodePort
  externalTrafficPolicy: Local
  selector: 
    run: nginx 
  • 实际测试的时候,考虑到调用解析时,跟 apiserver 通信会加大 etcd 的压力,所以使用上面的方式给 Service 绑定 10.254.100.100 这个 clusterIP

 

posted on 2018-11-14 17:19  冰冰爱学习  阅读(250)  评论(0编辑  收藏  举报

导航