Kubernetes 命令行 -- 检查与调试
命令 | 解释 |
---|---|
kubectl get <type> <name> | 查看某种类型资源 |
kubectl describe <type> <name> | 检查某特定资源实例 |
kubectl logs | 检查某pod的日志 |
kubectl exec | 在容器内执行命令 |
资源名称 | 解释 |
---|---|
NewReplicaSet | Replication Controller 保证副本数量 |
OldReplicaSets | 历史版本记录 |
实际操作:
1. 执行命令: kubectl get deployment
#输出:
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx 1 1 1 1 4m
DESIRED:期待的数量
current: 当前的数量
up-to-date: 已经是最近版本的数量
available: 能够提供服务的版本
AGE: 运行时长
2. 执行命令:kubectl get pods
输出:
NAME READY STATUS RESTARTS AGE
nginx-65899c769f-qjlfj 1/1 Running 0 4m
3. 执行命令: kubectl describe deployments nginx
Name: nginx
Namespace: default
CreationTimestamp: Sun, 28 Oct 2018 21:46:00 +0800
Labels: run=nginx
Annotations: deployment.kubernetes.io/revision: 1
Selector: run=nginx
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: run=nginx
Containers:
nginx:
Image: nginx
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-65899c769f (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 8m40s deployment-controller Scaled up replica set nginx-65899c769f to 1
4.执行命令: kubectl get replicaset
NAME DESIRED CURRENT READY AGE
nginx-65899c769f 1 1 1 16m
5.执行命令:kubectl describe rs nginx-65899c769f
Name: nginx-65899c769f
Namespace: default
Selector: pod-template-hash=2145573259,run=nginx
Labels: pod-template-hash=2145573259
run=nginx
Annotations: deployment.kubernetes.io/desired-replicas: 1
deployment.kubernetes.io/max-replicas: 2
deployment.kubernetes.io/revision: 1
Controlled By: Deployment/nginx
Replicas: 1 current / 1 desired
Pods Status: 1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: pod-template-hash=2145573259
run=nginx
Containers:
nginx:
Image: nginx
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 20m replicaset-controller Created pod: nginx-65899c769f-qjlfj
6.执行命令:kubectl get pods nginx-65899c769f-qjlfj -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-65899c769f-qjlfj 1/1 Running 0 22m 172.17.0.5 minikube
7.执行命令 :kubectl exec -it nginx-65899c769f-qjlfj /bin/bash
登录pods
8.执行命令:kubectl create -f nginx.svc.yaml
service/nginx created
9.执行命令: kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h
nginx NodePort 10.102.111.71 <none> 8888:30001/TCP 43s
10.kubectl describe svc
Name: kubernetes
Namespace: default
Labels: component=apiserver
provider=kubernetes
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP: 10.96.0.1
Port: https 443/TCP
TargetPort: 8443/TCP
Endpoints: 192.168.99.100:8443
Session Affinity: ClientIP
Events: <none>
Name: nginx
Namespace: default
Labels: app=nginx
Annotations: <none>
Selector: run=nginx
Type: NodePort
IP: 10.102.111.71
Port: http 8888/TCP
TargetPort: 80/TCP
NodePort: http 30001/TCP
Endpoints: 172.17.0.5:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
访问站点验证,其中192.168.99.100是minikube启动的虚拟机的ip:
360截图17571116437636.png
11.kubectl expose deploy nginx --type=NodePort --name=nginx-wls --port=80
service/nginx-wls exposed
12.kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h <none>
nginx NodePort 10.102.111.71 <none> 8888:30001/TCP 12m run=nginx
nginx-wls NodePort 10.105.144.9 <none> 80:31471/TCP 1m run=nginx
13. kubectl get endpoints
NAME ENDPOINTS AGE
kubernetes 192.168.99.100:8443 23h
nginx 172.17.0.5:80 12m
nginx-wls 172.17.0.5:80 1m