Kubernetes教程

关键词

  • pods、label、annotation、namespace

kubectl get

  • kubectl get pods
1
kubectl get pods --show-labels
  • kubectl get pods -L creation_method, env
  • kubectl get pods -l creation_method=manual
  • kubectl get pods -l env
  • kubectl get pods -l ‘!env’
  • kubectl get pods -l creation_method!=manual
  • kubectl get pods -l env in (prod, dev)
  • kubectl get pods -l env notin (prod, dev)
  • kubectl get pods -l app=pc, rel=dev
  • kubectl get nodes
  • kubectl get services
  • kubectl get secrets
  • kubectl get namespaces
  • kubectl get pods –namespace kube-system

kubectl run

  • kubectl run nginx –image=nginx
  • kubectl run k8s-tutorial-node –image yitianyigexiangfa/k8s_node_hello_world:1.0
  • kubectl run k8s-tutorial-node –image yitianyigexiangfa/k8s_node_hello_world:1.0 –port=8080

kubectl delete

  • kubectl delete pods k8s-tutorial-node
  • kubectl delete pods -l creation_method=manual
  • kubectl delete namespaces custom-namespaces
  • kubectl delete secrets regsecret
  • kubectl delete rs kubia –cascade=false

kubectl create

  • kubectl create deployment demo –image=yitianyigexiangfa/springboot-k8s-tutorial –dry-run=client -o=yaml > deployment.yaml
  • kubectl create service clusterip demo –tcp=8080:8080 –dry-run=client -o=yaml >> deployment.yaml
  • kubectl create namespace custom-namespace

kubectl apply

  • kubectl apply -f deployment.yaml

kubectl port-forward

1
2
kubectl port-forward svc/demo --address=0.0.0.0  8080:8080
kubectl port-forward k8s-tutorial-fortune --address=0.0.0.0 8080:80

kubectl config

  • kubectl config set-context kube-system-ctx –cluster=k8s-cluster1 –user=kubectl –namespace=kube-system

kubectl logs

  • kubectl logs k8s-tutorial-node
  • kubectl logs k8s-tutorial-node -c redis

kubectl label

  • kubectl label pods k8s-tutorial-node creation_method=manual
  • kubectl label pods k8s-tutorial-node env=prod –overwrite

kubectl annotation

  • kubectl annotation pods k8s-tutorial-node myCompany.com/someAnnotaion=”foo bar”

kubectl edit

  • kubectl edit replicationcontroller kubia

kubectl scale

  • kubectl scale rc kubia –replicas=3

kubectl exec

1
kubectl exec k8s-tutorial-fortune -c html-generator -- cat /var/htdocs/index.html