-
Too many kubectl commands too long to remember?
- View resource abbreviations
Kubectl the describe the enterCopy the code
- Configure the kubectl autocomplete command
source <(kubectl completion bash) Copy the code
-
Kubectl write yaml too tired, find sample too troublesome?
- Run the run command
kubectl run --image=nginx my-deploy -o yaml --dry-run > my-deploy.yaml Copy the code
- Export using the get command
kubectl get statefulset/foo -o=yaml --export > new.yaml Copy the code
- The spelling of the field below Pod affinity is forgotten
kubectl explain pod.spec.affinity.podAffinity Copy the code
-
Monitoring Cluster Components
- Cluster Status
kubectl cluster-info Copy the code
- More Cluster Information
kubectl cluster-info dump Copy the code
- Component metrics
curl localhost:10250/stats/summary Copy the code
- Component monitoring status
curl localhost:10250/healthz Copy the code
-
Manage K8s component logs
#Component log /var/log/kube-apiserver.log /var/log/kube-proxy.log /var/log/kube-controller-manager.log /var/log/kubelet.log Copy the code
- Use systemd for management
journalctl -u kubelet Copy the code
- Deploy using the K8s plug-in
kubectl logs -f kube-proxy Copy the code
-
Manage K8s application logs
- Intercepted from container standard output
kubectl logs -f {pod name} -c {container name} docker logs -f {docker name} Copy the code
- Log files are mounted to the host directory
apiVersion: v1 kind: Pod metadata: name: test-pod spec: containers: - image: test-webserver name: test-container volumeMounts: - mountPath: /log name: log-volume volumes: - name: log-volume hostPath: path: /var/k8s/log Copy the code
-
Deployment Upgrade and rollback
- Create a Deployment
kubectl run {deployment} --image={image} --replicas={rep.} Copy the code
- Upgrade Deployment
Kubectl set image deployment/nginx-deployment nginx=nignx:1.9.1 kubectl set resources deployment/nginx-deployment -c=nginx --limits=cpu=200m,memory=512MiCopy the code
- Upgrade strategy
minReadySeconds: 5 strategy: type: RollingUpdata maxSurge: 1 # default 25% maxUnavailable: 1 # default 25% Copy the code
- Suspension of Deployment
kubectl rollout pause deployment/nginx-deployment Copy the code
- Restore the Deployment
kubectl rollout resume deployment/nginx-deployment Copy the code
- Querying the Upgrade Status
kubectl rollout status deployment/nginx-deployment Copy the code
- Querying Upgrade History
kubectl rollout history deploy/nginx-deployment kubectl rollout history deploy/nginx-deployment --revision=2 Copy the code
- The rollback
kubectl rollout undo deployment/nginx-deployment --to-revision=2 Copy the code
- Applied elastic expansion
kubectl scale deployment nginx-deployment --replicas=10 Copy the code
- Heapster interconnects with HPA
kubectl autoscale deployment nginx-deployment --min=10 --max=15 --cpu-percent=80 Copy the code