系列文章
- 容器技术探索
- 单机容器网络
- 跨主机容器网络
- 容器运行时介绍
- Iptables 介绍
- K8S 集群部署
- K8S CNI 网络
- K8S 作业管理
- K8S 证书管理
- K8S Gateway
- Istio 实战笔记
- K8S 服务&Ingress
- K8S 持久化与数据挂载
常用命令
kubectl
-
污点添加和去除:
kubectl taint nodes ctrlnode node-role.kubernetes.io/control-plane:NoSchedule
kubectl taint nodes ctrlnode node-role.kubernetes.io/control-plane:NoSchedule-
-
节点标签:
kubectl label node node1 node-role.kubernetes.io/worker=worker
kubectl label nodes ctrlnode pvtype-
-
根据标签查询
Pod
:kubectl get pods -l app=nginx -owide
-
Pod
扩缩容:kubectl scale --current-replicas=2 --replicas=3 deployment/nginx-deployment
-
查询
Pod
中的容器:kubectl get pods nginx-deployment-848dd6cfb5-2gvg9 -o jsonpath={.spec.containers[*].name}
-
进入
Pod
中的容器:kubectl exec nginx-deployment-848dd6cfb5-2gvg9 -n default -it -c nginx -- /bin/bash
kubectl -n kube-system exec ds/cilium -- cilium status
-
Service
创建:从
deploy
创建服务
kubectl expose deploy nginx-deployment --port=8080 --target-port=80 --type=ClusterIP --name=nginx-deploy-clusterip-svc
-
创建
Pod
:创建并且Attach
kubectl run mytools -it --rm --image=praqma/network-multitool --image-pull-policy=IfNotPresent --command -- /bin/bash
仅创建
kubectl run mytools --image=praqma/network-multitool --image-pull-policy=IfNotPresent
-
更新镜像:
kubectl set image -n deploy-test deployment/nginx-deploy nginx=nginx:1.16.1 --record
kubectl patch statefulset nginx-sts --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"nginx:1.16.1"}]'
-
滚动更新历史:
kubectl rollout history -n deploy-test deployment/nginx-deploy
-
回滚:
kubectl rollout undo -n deploy-test deployment/nginx-deploy --to-revision=1
-
重启
Deploy
:kubectl rollout restart deployment cert-manager -n cert-manager
crictl
-
查询容器
PID
:crictl inspect -o go-template --template "{{ .info.pid }}" 15f86364ed865
-
进入容器:
nsenter -a -t $(crictl inspect -o go-template --template '{{.info.pid}}' 6a5985ec11357)
ctr
-
导入镜像:
ctr images import --platform linux/amd64 --base-name michael/netperf michael_netperf.tar
docker
-
查询容器
PID
:docker inspect --format "{{ .State.Pid }}" 52d2b3478c88
-
导出镜像
docker save -o michael_netperf.tar michael/netperf:arm64 michael/netperf:amd64
gzip michael_netperf.tar
-
导入镜像
docker load < busybox.tar.gz
docker load --input fedora.tar
-
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx build --platform linux/arm64 -t michael/netperf --load .
-
删除
<none>
镜像:docker rmi -f $(docker images -f "dangling=true" -q)
-
镜像编译设置代理:
设置代理
docker build -t rb-dev:musl --build-arg https_proxy=http://1127.0.0.1:3128 --build-arg http_proxy=http://127.0.0.1:3128 .