容器操作
- 常用命令
# 获得所有布署
kubectl get svc --all-namespaces
# 获得所有容器
kubectl pod svc --all-namespaces
# 修改布署文件
kubectl edit svc/<svc name> -n <namespace>
# 强制删除特定pods
#kubectl delete pods cloudagile-mariadb-0 -n intelligence-data-lab –grace-period=0 --force
# 删除集群失败的pods
kubectl get pods --field-selector=status.phase=Failed --all-namespaces |awk '{ system("kubectl delete pod "$2" -n "$1) }'
# 强制删除Terminating状态的pods
kubectl get pods --all-namespaces |grep Terminating||grep -w "0/1"|awk '{ system("kubectl delete pod "$2" -n "$1" --grace-period=0 --force") }'
# 删除空间
kubectl delete namespace <namespace>
# 修改部署的节点数
kubectl scale --replicas=2 deployment/serviceutil
# 回滚
kubectl rollout undo deployment/
- 有状态容器重启
有状态容器重启要节点数改为0,再恢复到原来的值。
rancher上的操作可以直接伸缩容器
# 修改部署的节点数
kubectl scale --replicas=2 deployment/<pod name>
标记标签(可以指定布署到标签)
# 查询所有标签
kubectl get nodes --show-labels
# 需要将对外的那台主机进行标记标签
kubectl label nodes 192.168.71.104 type=outer
污点(其它pod不分配到污点机器, 容忍的机器可以布署到这台机器)
- 设置node
# 为主机设置污点标签
kubectl taint nodes 192.168.xxx.xxx skywalking_namespace=skywalking:NoExecute --overwrite
# 设置调度标签
kubectl label nodes 192.168.xxx.xxx skywalking_namespace=skywalking --overwrite
- 配置pod
# 为部署设置污点容忍
tolerations:
- key: "skywalking_namespace"
operator: "Equal"
value: "skywalking"
effect: "NoExecute"
# 设置标签符合
nodeSelector:
tristan_namespace: "skywalking"
k8s network
- 开启服务
---
apiVersion: v1
kind: Service
metadata:
name: kibana4log
spec:
selector:
app: kibana4log
ports:
- protocol: TCP
port: 80
targetPort: 5601
- 开启dns
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: kibana-ingress
namespace: logging
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/auth-type: "basic"
traefik.ingress.kubernetes.io/auth-secret: "basic-auth"
spec:
rules:
- host: kibana.java.yibainetwork.com
http:
paths:
- backend:
serviceName: kibana4log
servicePort: 80
- 转发内部网络到外部
kubectl port-forward service/ok 8080:8080 8081:80 -n the-project
docker反向工程
-
docker image inspect
-
使用dockerfile-from-image工具
# 安装nodejs
curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm install
npm run build
npm -v
npx dockerfile-from-image tensorflow/tensorflow:latest-py3 > dockerfile
es清除数据
curl -XGET 'http://127.0.0.1:9200/_cat/indices/?v'
GET /_cat/indices/?v
curl -XDELETE 'http://127.0.0.1:9200/索引名字'
DELETE /*-2019.07*
docker清除镜像
docker system prune -a
es减少副本数
.spec.revisionHistoryLimit
查看详情
kubectl describe node <节点名称>
kubectl get node -o wide