Kubernetes操作

1、Deployment和Pod

文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: lmsia-abc-server-deployment
spec:
  selector:
    matchLabels:
      app: lmsia-abc-server
  replicas: 2
  template:
    metadata:
      labels:
        app: lmsia-abc-server
    spec:
      containers:
      - name: lmsia-abc-server-ct
        image: coder4/lmsia-abc-server:latest
        ports:
        - containerPort: 8080
        - containerPort: 3000

创建

kubectl apply -f ./lmsia-abc-server-deployment.yaml

查看关联的Pod

kubectl get pods -l app=lmsia-abc-server

删除

kubectl delete deployment lmsia-abc-server-deployment

强制重启Pod

kubectl get pod PODNAME -n NAMESPACE -o yaml | kubectl replace --force -f -

强制删除Deployment (如果之前设置了自动重启)

kubectl delete deployment DEPLOYMENT_NAME --grace-period=0 --force

 

2、Service

文件

apiVersion: v1                                                                                           
kind: Service
metadata:                                                                                                
  name: lmsia-abc-server-service
spec:                                                                                                    
  selector:                                                                                              
    app: lmsia-abc-server
  ports:                                                                                                 
  - name: http
    protocol: TCP                                                                                        
    port: 8080         

创建

kubectl apply -f lmsia-abc-server-service.yaml

查看

kubectl describe service lmsia-abc-server-service

删除

kubectl delete service lmsia-abc-server-service

3、persistant volume

文件:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: openldap 
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath:
    path: /data/openldap/

列出:

kubectl get pv

查看

kubectl describe pv openldap

删除

kubectl delete pv openldap

 

 

 

 

 

 

Leave a Reply

Your email address will not be published.