• 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 {
             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 {
             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" "-"
    

      

    草都可以从石头缝隙中长出来更可况你呢
  • 相关阅读:
    『CEO日报』-商业版的今日头条,《财富》(中文版)出品 on the App Store
    Hosted Web Scraper Online
    名巢靓家_百度百科
    服装消费3.0时代的试验者: Pretty Yes 通过穿搭问答解决中产女性的时尚衣着问题
    好市多_百度百科
    新闻:融资600万 他用一套系统优化15大HR工作场景 精简入转调离 月开通214家 | IT桔子
    眨眼网杨莹,能写代码能玩时尚的美女CEO-搜狐
    新闻:全球独立设计师平台眨眼网推出男装系列 | IT桔子
    漏洞盒子 | 互联网安全测试平台
    浙江设立200亿元省产业基金·杭州日报
  • 原文地址:https://www.cnblogs.com/rdchenxi/p/10758135.html
Copyright © 2020-2023  润新知