k8s部署测试实例

查看运行中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" "-"

  

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...