k8s 關於POD命令


使用資源配置清單創建POD

1.使用命令行創建一個pod

kubectl create deployment nginx --image=nginx:alpine

2.將剛才創建的pod配置到處成yaml格式

kubectl get pod -o yaml > nginx-pod.yaml

3.最簡化的資源清單

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:alpine
    imagePullPolicy: IfNotPresent
    ports:
    - name: http
      containerPort: 80

4.刪除命令行創建的資源

kubectl delete deployments.apps nginx

5.應用資源配置清單

kubectl create -f nginx-pod.yaml
kubectl apply -f nginx-pod.yaml

6.查看pod信息

kubectl get pods
kubectl get pod -o wide

7.實時查看pod創建和刪除信息

kubectl get pods -w

8.查看pod詳細信息

kubectl describe pod pod名稱
kubectl describe pod nginx

9.查看一個pod里的容器日志

kubectl logs pod名稱 -c pod當中的一個容器名
kubectl logs nginx-tomcat -c tomcat

10.進入pod中的一個容器

kubectl exec -it kod名稱 -c 容器名稱 /bin/bash
kubectl exec -it game -c game /bin/bash

11.刪除一個pod(用資源清單起的)

kubectl delete pods pod名稱
kubectl delete pods game


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM