Kubernetes Common Commands

Source: Internet
Author: User

Kubectl common creation and viewing operations
    1. Create deployment
kubectl create -f nginx-deployment.yaml
    1. View Deployment

      kubectl get deployment
    2. View Pods
kubectl get pod -o wide
    1. View details for a pod
      kubectl describe pod nginx-deployment-75d56bb955-bzkv4
    2. Test pod Access
      curl --head 10.0.0.2
    3. Update deployment
      kubectl set image deployment/nginx-deployment nginx=nginx:1.12.2 --record
    4. View Deployment
      kubectl get deployment -o wide
    5. View update history (you need to add parameters when performing creation and updating --record )
      kubectl rollout history deployment
    6. To view a specific version history
      kubectl rollout history deployment/nginx-deployment --revision=2
    7. Quick rollback to previous version

      kubectl rollout undo deployment/nginx-deployment
    8. Capacity expansion and shrinking capacity
      kubectl  scale deployment nginx-deployment --replicas 2
    9. View back-end load and forwarding rules
      ipvsadm -Ln
Kubectl Operation Example

1. Create a Resource object

    • Create service and RC using Yaml file:
      kubectl create -f my-service.yaml -f my-rc.yaml
    • Create an operation based on all the. Yaml. yml. json file definitions under the <dir> directory:
      kubectl create -f <dir>
    1. View Resource Objects
      kubectl get podskubectl get rc,service

3. Describe the resource object

    • Show Node's details
      kubectl describe nodes <node-name>
    • Show pod Details
      kubectl describe pods/<pod-name>
    • Display pod information managed by RC
      kubectl describe pods <rc-name>
      1. Delete a Resource object
    • To delete a pod based on a name defined by Pod.yaml:
      kubectl delete -f pod.yaml
    • Delete all pods and service that contain a label:
      kubectl delete pods, services -l name=<label-name>
    • Delete all pods:
      kubectl delete pods --all
    1. command to execute container

      • Executes the date command for the pod, which is performed by default using the first container in the pod:
        kubectl exec <pod-name> date
      • Specify a container in the pod to execute the date command
        kubectl exec <pod-name> -c <container-name> date
      • Using bash to get a TTY for a container in the pod is equivalent to a login container:
        kubectl exec -it <pod-name> -c <container-name> /bin/bash
    2. View the logs for a container
      • To view a log of the container output to stout:
        kubectl logs <pod-name>
      • Trace the log of the view container, which corresponds to the result of the TAIL-F command:
        kubectl logs -f <pod-name> -c <container-name>

Kubernetes Common Commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.