创建一个pod测试一下集群

在主master 10.192.27.100 测试一下

[root@localhost ~]# kubectl run nginx --image=nginx
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx created

[root@localhost ~]# kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7cdbd8cdc9-428gx   1/1     Running   0          3m47s

[root@localhost ~]# kubectl log nginx-7cdbd8cdc9-428gx  #查看日志被拒绝
log is DEPRECATED and will be removed in a future version. Use logs instead.
Error from server (Forbidden): Forbidden (user=system:anonymous, verb=get, resource=nodes, subresource=proxy) ( pods/log nginx-7cdbd8cdc9-428gx)
[root@localhost ~]# kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous  #解决办法  授权
clusterrolebinding.rbac.authorization.k8s.io/cluster-system-anonymous created
##########################
#这是一个RBAC错误。用户无权查看日志。如果您拥有具有群集管理员权限的用户,则可以使用此方法修复此错误
#kubectl create clusterrolebinding xxx --user system:anonymous --clusterrole cluster-admin
#注意:提供匿名用户群集管理员角色不是一个好主意。但是会修复这个问题。

[root@localhost ~]# kubectl log nginx-7cdbd8cdc9-428gx
log is DEPRECATED and will be removed in a future version. Use logs instead.

[root@localhost ~]# kubectl get pods -o wide  #查看新建的pod分配到哪个node中?
NAME                     READY   STATUS    RESTARTS   AGE   IP           NODE           NOMINATED NODE   READINESS GATES
nginx-7cdbd8cdc9-428gx   1/1     Running   0          12m   172.17.8.2   10.192.27.115   <none>           <none>
[root@localhost ~]# 

 

 

 

 

 

在node01 10.192.27.115 查看

[root@localhost cfg]# docker ps -a
CONTAINER ID        IMAGE                                                                 COMMAND                  CREATED             STATUS                    PORTS               NAMES
e5f7318cef5c        nginx                                                                 "nginx -g 'daemon of…"   11 minutes ago      Up 11 minutes                                 k8s_nginx_nginx-7cdbd8cdc9-428gx_default_d251c725-cb99-11e9-8fb3-000c2988ee76_0
5adf59af0078        registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0   "/pause"                 13 minutes ago      Up 12 minutes                                 k8s_POD_nginx-7cdbd8cdc9-428gx_default_d251c725-cb99-11e9-8fb3-000c2988ee76_0
f28b7dab392b        centos:7                                                              "bash"                   37 hours ago        Exited (1) 37 hours ago                       kind_lehmann
[root@localhost cfg]# 
[root@localhost cfg]# curl 172.17.8.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>
[root@localhost cfg]# 

 

 

再次在master上查看日志

[root@localhost ~]# kubectl log nginx-7cdbd8cdc9-428gx
log is DEPRECATED and will be removed in a future version. Use logs instead.
172.17.8.1 - - [31/Aug/2019:03:05:08 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
[root@localhost ~]# 

 

posted @ 2019-11-15 09:19  冥想心灵  阅读(24)  评论(0编辑  收藏  举报