您现在的位置是: 网站首页 >Kubernetes >Docker&Kubernetes技术全解 Kubernetes
【K8s+Docker技术全解】13.验证kubernets集群
admin2020年10月19日 23:08 【Docker | Kubernetes | Linux 】 1791人已围观
Docker&Kubernetes技术全解简介 Kubernetes 是一个可移植的、可扩展的开源平台,用于管理容器化的工作负载和服务,可促进声明式配置和自动化。Kubernetes 拥有一个庞大且快速增长的生态系统。Kubernetes 的服务、支持和工具广泛可用。 课程来自老男孩教育学习总结。
## 验证kubernets集群 ### 在任意运算节点创建资源配置清单 在任意一个运算节点,常见一个资源配置清单,例如在 k8s99-151 上创建 ```bash [root@k8s99-151 ~]# cd [root@k8s99-151 ~]# vim /root/nginx-ds.yaml ``` 添加下面的内容 ```yaml # 创建资源配置清单 apiVersion: apps/v1 kind: DaemonSet metadata: name: nginx-ds spec: template: metadata: labels: app: nginx-ds spec: containers: - name: my-nginx image: harbor.study.com/public/nginx:latest ports: - containerPort: 80 ``` #### 解决nginx-ds.yaml新版配置错误问题 创建资源 ```bash [root@k8s99-151 ~]# kubectl create -f nginx-ds.yaml error: unable to recognize "nginx-ds.yaml": no matches for kind "DaemonSet" in version "extensions/v1beta1" # 将配置文件内的api接口修改为 apps/v1 ,导致原因为之间使用的kubernetes 版本弃用了原来的extensions/v1beta1接口 # 查看当前可用的API版本 [root@k8s99-151 ~]# kubectl api-versions admissionregistration.k8s.io/v1 admissionregistration.k8s.io/v1beta1 apiextensions.k8s.io/v1 apiextensions.k8s.io/v1beta1 apiregistration.k8s.io/v1 apiregistration.k8s.io/v1beta1 apps/v1 authentication.k8s.io/v1 authentication.k8s.io/v1beta1 authorization.k8s.io/v1 authorization.k8s.io/v1beta1 autoscaling/v1 autoscaling/v2beta1 autoscaling/v2beta2 batch/v1 batch/v1beta1 certificates.k8s.io/v1beta1 coordination.k8s.io/v1 coordination.k8s.io/v1beta1 discovery.k8s.io/v1beta1 events.k8s.io/v1beta1 extensions/v1beta1 networking.k8s.io/v1 networking.k8s.io/v1beta1 node.k8s.io/v1beta1 policy/v1beta1 rbac.authorization.k8s.io/v1 rbac.authorization.k8s.io/v1beta1 scheduling.k8s.io/v1 scheduling.k8s.io/v1beta1 storage.k8s.io/v1 storage.k8s.io/v1beta1 v1 # 将extensions/v1beta1修改为apps/v1后,又报错 [root@k8s99-151 ~]# kubectl create -f nginx-ds.yaml error: error validating "nginx-ds.yaml": error validating data: ValidationError(DaemonSet.spec): missing required field "selector" in io.k8s.api.apps.v1.DaemonSetSpec; if you choose to ignore these errors, turn validation off with --validate=false # 参考网上查看这个错误的帮助 [root@k8s99-151 ~]# kubectl explain DaemonSet.spec.selector KIND: DaemonSet VERSION: apps/v1 RESOURCE: selector <Object> DESCRIPTION: A label query over pods that are managed by the daemon set. Must match in order to be controlled. It must match the pod template's labels. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. FIELDS: matchExpressions <[]Object> matchExpressions is a list of label selector requirements. The requirements are ANDed. matchLabels <map[string]string> matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. ``` 在配置文件中增加`selector:`配置后,再次创建 ```bash [root@k8s99-151 ~]# vim nginx-ds.yaml ``` 配置文件如下,在`spec:`中增加了 ```yaml selector: matchLabels: app: nginx-ds ``` #### nginx-ds.yaml 配置文件 ```yaml apiVersion: apps/v1 kind: DaemonSet metadata: name: nginx-ds spec: selector: matchLabels: app: nginx-ds template: metadata: labels: app: nginx-ds spec: containers: - name: my-nginx image: harbor.study.com/public/nginx:latest ports: - containerPort: 80 ``` 再次创建成功了 ```bash [root@k8s99-151 ~]# kubectl create -f nginx-ds.yaml daemonset.apps/nginx-ds created ``` #### 查看使用配置清单生成的pod ```bash [root@k8s99-151 ~]# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-ds-5txgt 1/1 Running 0 2m4s nginx-ds-g27vj 1/1 Running 0 2m4s [root@k8s99-151 ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-ds-5txgt 1/1 Running 0 2m37s 172.99.152.2 k8s99-152.host.com <none> <none> nginx-ds-g27vj 1/1 Running 0 2m37s 172.99.151.2 k8s99-151.host.com <none> <none> ``` ### 使用curl测试访问nginx 上面得到了两个IP,现在可以通过`curl`测试 ```bash [root@k8s99-151 ~]# curl 172.99.151.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> # 可以得到nginx的主页信息 [root@k8s99-151 ~]# curl 172.99.152.2 curl: (7) Failed connect to 172.99.152.2:80; 拒绝连接 # 无法访问,原因是跨宿主机的Docker容器还不能通信 ``` 在另一台上访问也是 ```bash [root@k8s99-152 ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-ds-5txgt 1/1 Running 0 12m 172.99.152.2 k8s99-152.host.com <none> <none> nginx-ds-g27vj 1/1 Running 0 12m 172.99.151.2 k8s99-151.host.com <none> <none> [root@k8s99-152 ~]# curl 172.99.152.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@k8s99-152 ~]# curl 172.99.151.2 curl: (7) Failed connect to 172.99.151.2:80; 拒绝连接 # 就不能访问了 ``` 使用flannel这个组件可以解决这个问题。后面讲到。 ### 使用kubectl获取所有状态 ```bash [root@k8s99-151 ~]# kubectl get cs NAME STATUS MESSAGE ERROR scheduler Healthy ok controller-manager Healthy ok etcd-1 Healthy {"health":"true"} etcd-2 Healthy {"health":"true"} etcd-0 Healthy {"health":"true"} [root@k8s99-151 ~]# kubectl get node NAME STATUS ROLES AGE VERSION k8s99-151.host.com Ready master,node 9d v1.18.2 k8s99-152.host.com Ready master,node 8d v1.18.2 [root@k8s99-151 ~]# kubectl get pod NAME READY STATUS RESTARTS AGE nginx-ds-5txgt 1/1 Running 1 16h nginx-ds-g27vj 1/1 Running 1 16h ```
很赞哦! (1)
相关文章
文章交流
- emoji
当前用户
未登录,点击 登录专题目录
- 【K8s+Docker技术全解】01.Kubernetes快速入门概述
- 【K8s+Docker技术全解】02.k8s搭建环境准备-准备DNS服务
- 【K8s+Docker技术全解】03.k8s搭建环境准备-证书签发环境和Docker环境
- 【K8s+Docker技术全解】04.运维主机部署Harbor环境
- 【K8s+Docker技术全解】05.部署k8s分布式数据库etcd
- 【K8s+Docker技术全解】06.Master主控节点服务-部署kube-apiserver集群
- 【K8s+Docker技术全解】07.Master主控节点服务-配置nginx4层反向代理
- 【K8s+Docker技术全解】08.Master主控节点服务-keepalived配置vip
- 【K8s+Docker技术全解】09.Master主控节点服务-部署controller-manager
- 【K8s+Docker技术全解】10.Master主控节点服务-部署kube-scheduler、检查集群状态
- 【K8s+Docker技术全解】11.Node运算节点服务-部署kubelet
- 【K8s+Docker技术全解】12.Node运算节点服务-部署kube-proxy
- 【K8s+Docker技术全解】13.验证kubernets集群
- 【K8s+Docker技术全解】14.关于k8s证书
- 【K8s+Docker技术全解】15.管理k8s核心资源方法
- 【kubernetes】使用kubeadm快速搭建k8s集群学习