k8s study concluded (b)

Common Commands

  • Create a namespace

kubectl create namespace test

Or by performing kubectl create -f test.yml

apiVersion: v1
kind: Namespace
metadata:
    name: test
  • Create a pod on the basis of the namespace
#在test上使用nginx image创建一个名叫mypod的pod,设置端口为80
kubectl run mypod --image=nginx --restart=Never --port=80 --namespace=test
  • View pod status
#kubectl get pod -n test
NAME                     READY   STATUS              RESTARTS   AGE
mypod                    1/1     Running   0          2m47s


# kubectl get pod -n test -o wide
NAME                     READY   STATUS      RESTARTS   AGE     IP            NODE    NOMINATED NODE   READINESS GATES
mypod                    0/1     Completed   0          37m     172.17.1.32   node2   <none>           <none>
  • View details pod
kubectl describe pod -n mypod
  • Adjust pod image version
kubectl set image pod mypod mypod=nginx:2.3.5 --namespace=test

login pod, the operation

kubectl exec test -it --namespace=test == /bin/sh
# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
# pwd
/
  • Create a temporary pod
kubectl run busybox --image=busybox --rm -it --restart=Never -n test -- /bin/sh
  • View Log pod
kubectl logs mypod -n test
  • Delete pod, namespace
#kubectl delete pod mypod --namespace=test
#kubectl delete namespace test

 

Published 141 original articles · won praise 14 · views 90000 +

Guess you like

Origin blog.csdn.net/haiziccc/article/details/104560465