查看运行中pod,并运行一个容器

[root@mast-1 k8s]# kubectl get pods
No resources found.
[root@mast-1 k8s]# kubectl run nginx --image=nginx   运行nginx容器
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed i
n a future version. Use kubectl create instead.deployment.apps/nginx created
[root@mast-1 k8s]# kubectl get pods
NAME                    READY   STATUS              RESTARTS   AGE
nginx-dbddb74b8-h59k2   0/1     ContainerCreating   0          3s
[root@mast-1 k8s]# kubectl get all   查看运行所有的资源
NAME                        READY   STATUS    RESTARTS   AGE
pod/nginx-dbddb74b8-h59k2   1/1     Running   0          85s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   8h

NAME                    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx   1         1         1            1           86s

NAME                              DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-dbddb74b8   1         1         1       86s
[root@mast-1 k8s]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP        8h
nginx        NodePort    10.0.0.82    <none>        80:31330/TCP   103s

 两个节点访问同一个容器

[root@node-1 kubernetes]# curl 10.0.0.82:80
<!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@node-2 cfg]#  curl 10.0.0.82:80
<!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>

  浏览器里访问两个node任意的IP:31330端口

 

 

 master 节点查看日志,报错并解决

[root@mast-1 k8s]# kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
nginx-dbddb74b8-h59k2   1/1     Running   2          33m
[root@mast-1 k8s]# kubectl logs nginx-dbddb74b8-h59k2
error: You must be logged in to the server (the server has asked for the client to provide credentials ( pods/log nginx-dbddb74b8-h59k2))
[root@node-1 kubernetes]# cat cfg/kubelet.config 

kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 192.168.10.13
port: 10250
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2 
clusterDomain: cluster.local.
failSwapOn: false
--------------添加下面参数-----
authentication:
  anonymous:
    enabled: true
[root@node-2 cfg]# vi kubelet.config 


kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 192.168.10.14
port: 10250
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2
clusterDomain: cluster.local.
failSwapOn: false
----------------------------
authentication:
  anonymous:
    enabled: true
重启
[root@node-1 kubernetes]# systemctl restart kubelet.service 
[root@node-2 cfg]# systemctl restart kubelet.service
[root@mast-1 k8s]# kubectl create clusterrolebinding  cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous
clusterrolebinding.rbac.authorization.k8s.io/cluster-system-anonymous created
[root@mast-1 k8s]# kubectl logs nginx-dbddb74b8-h59k2
10.0.0.82 - - [23/Apr/2019:09:59:53 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
10.0.0.82 - - [23/Apr/2019:10:02:55 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
172.17.82.0 - - [23/Apr/2019:10:03:11 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
172.17.8.1 - - [23/Apr/2019:10:06:41 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3554.0 Safari/537.36" "-"
2019/04/23 10:06:49 [error] 6#6: *4 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.8.1, server: localhost, request: "GET /favicon.ico HTTP/1.
1", host: "192.168.10.13:31330", referrer: "http://192.168.10.13:31330/"172.17.8.1 - - [23/Apr/2019:10:06:49 +0000] "GET /favicon.ico HTTP/1.1" 404 556 "http://192.168.10.13:31330/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrom
e/71.0.3554.0 Safari/537.36" "-"

  动态查看

 

[root@mast-1 k8s]# kubectl logs nginx-dbddb74b8-h59k2 -f
10.0.0.82 - - [23/Apr/2019:09:59:53 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
10.0.0.82 - - [23/Apr/2019:10:02:55 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
172.17.82.0 - - [23/Apr/2019:10:03:11 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
172.17.8.1 - - [23/Apr/2019:10:06:41 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3554.0 Safari/537.36" "-"
2019/04/23 10:06:49 [error] 6#6: *4 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.8.1, server: localhost, request: "GET /favicon.ico HTTP/1.
1", host: "192.168.10.13:31330", referrer: "http://192.168.10.13:31330/"172.17.8.1 - - [23/Apr/2019:10:06:49 +0000] "GET /favicon.ico HTTP/1.1" 404 556 "http://192.168.10.13:31330/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrom
e/71.0.3554.0 Safari/537.36" "-"

  

转载于:https://www.cnblogs.com/rdchenxi/p/10758135.html

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐