Open ysl2 opened 5 months ago
kubectl get pods --all-namespaces
kubectl get pods -A
kubectl get pods -n <namespace>
kubectl get deployment -n <namespace>
kubectl get replicaset -n <namespace>
kubectl exec -it ysl-5c8cc9ddd9-q9zq6 -n my-namespace -- /bin/bash
kubectl describe deployment -n ysl-newnamespace ysl-check-env | grep -i newreplicaset: | awk '{print $2}'
# 下面这个好用
kubectl exec -n ysl-newnamespace -it "$(kubectl get pods -n ysl-newnamespace -l app=ysl-check-env | awk 'NR > 1 {print $1}')" -- /bin/bash
# 手动触发deployment更新
kubectl patch -n ysl-newnamespace deployment ysl-check-env -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"$(date +'%s')\"}}}}}"
创建一个deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: ysl-check-env-new
namespace: ysl-newnamespace
spec:
replicas: 1
selector:
matchLabels:
app: ysl-check-env-new
template:
metadata:
labels:
app: ysl-check-env-new
spec:
containers:
- name: ysl-check-env-new
image: registry.abcde.com/fgh/ijk-tools-x86:latest
kubectl apply -f deployment.yaml
或者通过命令创建:
kubectl create deployment -n ysl check-env-new --image=aabbcc.def.ghi.com/tcs/jklmn-tools-x86:latest --replicas=1
或者绕过kubectl,直接通过docker创建容器:
docker run --network host -it aabbcc.def.ghi.com/tcs/jklmn-tools-x86:latest /bin/bash
进入其中正在运行的pod
kubectl exec -n ysl-newnamespace -it "$(kubectl get pods -n ysl-newnamespace -l app=ysl-check-env-new | grep -i running | awk '{print $1}')" -- /bin/bash
手动触发deployment中的pod拉取新版本镜像
# kubectl set image -n {命名空间} deployment/{deployment名称} {容器名称}={镜像名}:latest
kubectl set image -n ysl-newnamespace deployment/ysl-check-env-new ysl-check-env-new=registry.abcde.com/fgh/ijk-tools-x86:latest
删掉deployment中没有在Running的pod
kubectl delete pod -n ysl-newnamespace "$(kubectl get pods -n ysl-newnamespace -l app=ysl-check-env-new | grep -vi running | awk 'NR > 1 {print $1}')"
# 查看当前使用的上下文信息
kubect config get-contexts
https://kubernetes.io/zh-cn/docs/home/
https://golangguide.top/%E6%9E%B6%E6%9E%84/%E4%BA%91%E5%8E%9F%E7%94%9F/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E7%82%B9/k8s%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E4%B9%88.html
https://geekhour.net/2023/12/23/kubernetes/ (Kubernetes-Cheat-Sheet.pdf)