加载中...

第七章 完成kubernetes集群部署并验证

在其中一运算个节点上操作就行
创建nginx资源配置清单的yaml文件

[root@hdss7-21 ~]# vim /opt/kubernetes/conf/nginx-ds.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
    name: nginx-ds
spec:
    template:
      metadata:
        labels:
          app: nginx-ds
      spec:
        containers:
        - name: my-nginx
          image: harbor.od.com/public/nginx:v1.7.9
          ports:
          - containerPort: 80

创建nginx资源

[root@hdss7-21 ~]# kubectl create -f  /opt/kubernetes/conf/nginx-ds.yaml
daemonset.extensions/nginx-ds created

查看pod

[root@hdss7-21 ~]# kubectl get pods
NAME             READY   STATUS    RESTARTS   AGE
nginx-ds-4ln28   1/1     Running   0          38s
nginx-ds-spdgm   1/1     Running   0          38s
[root@hdss7-21 ~]#  kubectl get pods -owide
NAME             READY   STATUS    RESTARTS   AGE   IP           NODE                NOMINATED NODE   READINESS GATES
nginx-ds-4ln28   1/1     Running   0          56s   172.7.22.2   hdss7-22.host.com   <none>           <none>
nginx-ds-spdgm   1/1     Running   0          56s   172.7.21.2   hdss7-21.host.com   <none>           <none>

在21主机上和22主机上只能访问自己创建的容器主机
例如,在21上访问172.7.21.2可以正常访问

[root@hdss7-21 ~]# curl 172.7.21.2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

访问172.7.22.2(宿主机在10.4.7.22上)却无法连接

[root@hdss7-21 ~]# curl 172.7.22.2
^C

原因是我们利用docker跨宿主机还不能通信,后面介绍的flannel可以解决跨主机通信问题

posted @ 2021-07-15 21:01  沾沾自喜的混子  阅读(103)  评论(0编辑  收藏  举报