k8s部署测试实例
查看运行中pod,并运行一个容器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | [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 |
两个节点访问同一个容器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | [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 节点查看日志,报错并解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | [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 " " -" |
动态查看
1 2 3 4 5 6 7 8 | [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 " " -" |
草都可以从石头缝隙中长出来更可况你呢
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏