二进制部署k8s集群方案之验证集群功能

2024-01-30 14:12:12 浏览数 (1)

二进制部署k8s集群方案之验证集群功能

养浩然之气,做博学之人

一、检查节点状态

代码语言:javascript复制
kubectl get nodes
#NAME         STATUS    ROLES     AGE       VERSION
#kube-node1   Ready     <none>    3h        v1.10.4
#kube-node2   Ready     <none>    3h        v1.10.4
#kube-node3   Ready     <none>    3h        v1.10.4

##都为 Ready 时正常。

二、创建测试文件

代码语言:javascript复制
cat > nginx-ds.yml <<EOF
apiVersion: v1
kind: Service
metadata:
  name: nginx-ds
  labels:
      app: nginx-ds
spec:
  type: NodePort
  selector:
      app: nginx-ds 
  ports:
    - name: http
      port: 80 
      targetPort: 80
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nginx-ds
  labels:
      addonmanager.kubernetes.io/mode: Reconcile
spec:
  template:
      metadata: 
           labels: 
                  app: nginx-ds
      spec:
            containers:
            - name: my-nginx
              image: nginx:1.7.9
              ports:
              - containerPort: 80
EOF

三、执行定义文件

代码语言:javascript复制
kubectl create -f nginx-ds.yml
#service "nginx-ds" created
#daemonset.extensions "nginx-ds" created

四、检查各 Node 上的 Pod IP 连通性

代码语言:javascript复制
kubectl get pods  -o wide|grep nginx-ds
#nginx-ds-p9p5x   1/1       Running    6          15h       192.30.32.2   docker110
#nginx-ds-rsrvl   1/1       Running    5          15h       192.30.97.2   docker112
#nginx-ds-rvbdl   1/1       Running    12         15h       192.30.18.2   docker111

若有没有起来的可执行:

代码语言:javascript复制
#kubectl describe pods nginx-ds-rsrvl 
#kubectl describe pods nginx-ds-rvbdl

可见,nginx-ds 的 Pod IP 分别是192.30.32.2、192.30.97.2、192.30.18.2,在所有 Node 上分别 ping 这三个 IP,看是否连通:

代码语言:javascript复制
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
  do
      echo ">>> ${node_ip}"
      ssh ${node_ip} "ping -c 1 192.30.18.2"
      ssh ${node_ip} "ping -c 1 192.30.97.2"
      ssh ${node_ip} "ping -c 1 192.30.32.2"
done

五、检查服务 IP 和端口可达性

代码语言:javascript复制
kubectl get svc |grep nginx-ds
#nginx-ds     NodePort    10.0.178.178   <none>        80:8536/TCP   9h

#可见:

#Service Cluster IP: 10.0.178.178

#服务端口:80

#NodePort 端口:8536

六、检查服务的 NodePort 可达性

代码语言:javascript复制
source /opt/k8s/bin/environment.shfor node_ip in ${NODE_IPS[@]}
  do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "curl ${node_ip}:8900"
  done

#预期输出 nginx 欢迎页面内容。

代码语言:text复制
#% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#                                 Dload  Upload   Total   Spent    Left  Speed
#  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0<!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>参考:

https://www.kubernetes.org.cn/3063.html

https://www.kubernetes.org.cn/3096.html

https://github.com/opsnull/follow-me-install-kubernetes-cluster

http://www.imooc.com/article/23355

https://www.docker.com/

0 人点赞