验证集群功能(在master节点上执行)
以一个nginx的service和deployment来验证集群功能
- 创建启动文件
mkdir /opt/k8s/yml cd /opt/k8s/yml cat > nginx.yml << EOF apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: type: NodePort selector: app: nginx ports: - name: http port: 80 targetPort: 80 nodePort: 8080 --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.9.1 ports: - containerPort: 80 EOF
- 启动服务
kubectl create -f nginx.yml
- 第一次启动时需要下载k8s.gcr.io/pause:3.1镜像,国内无法直接下载,造成服务无法启动,通过下面操作来解决
docker pull kubeimage/pause:3.1 docker tag kubeimage/pause:3.1 k8s.gcr.io/pause:3.1
- 第一次启动时需要下载k8s.gcr.io/pause:3.1镜像,国内无法直接下载,造成服务无法启动,通过下面操作来解决
- 观察服务启动情况
[email protected]:/opt/k8s/yml# kubectl get service -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 41h <none> nginx NodePort 10.254.8.25 <none> 80:8080/TCP 30m app=nginx [email protected]:/opt/k8s/yml# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deployment-56f8998dbc-955gf 1/1 Running 0 30m 172.30.78.2 slave <none> <none> [email protected]:/opt/k8s/yml# curl http://192.168.0.114:8080 <!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>
遇到问题
- k8s组件 kube-scheduler服务停掉,造成所有的pod都处于pending状态,没有任何events信息
- k8s组件kube-controller-manager服务停掉,造成所有的rs、rc都不创建,对应的deployment中没有任何events信息,NewReplicats
原文地址:https://www.cnblogs.com/gaofeng-henu/p/12594637.html
时间: 2024-10-01 11:43:59