Python列表操作
列表去除空值123i = [ "a", "", "", "b", "", "c", "" ]i = [ tmp for tmp in i if tmp ]print(i)
kubernetes节点维护流程
节点设置为SchedulingDisabled 其实就是打上污点 node.kubernetes.io/unschedulable:NoSchedule
命令
说明
kubectl cordon
将node设置为SchedulingDisabled, 不允许新的pod调度上来, 旧的pod不受影响
kubectl drain
先驱逐node上的pod, k8s会在其他节点重新创建, 然后将节点设置为 SchedulingDisabled
kubectl uncordon
恢复调度, 删除 SchedulingDisabled 污点
操作流程常规操作将节点上现有的pod驱逐, 不追求优雅
1kubectl drain <node> --delete-local-data=true --ignore-daemonsets=true --force
操作完毕后, 将节点恢复调度
1kubectl uncordon <node>
对集群无影响的操作先针对节点执行
1kubectl cordon <node>
然后等待节 ...
二进制部署Kuberntes 1.17.2
一些基本信息
说明
IP/段
SERVICE_CIDR
10.68.0.0/16
CLUSTER_CIDR / Pod CIDR
172.20.0.0/16
master1
10.0.0.51
master2
10.0.0.52
master3
10.0.0.53
vip
10.0.0.50
集群DNS的Cluster IP (kubelet需要配置)
10.68.0.2
高可用方案高可用主要有以下几种方案:
keepalived飘一个VIP,这种方案只能起到高可用的作用,并不能为apiserver做负载,且不够优雅
每个master节点部署一个负载均衡,后端配置的是所有的apiserver地址,然后使用keepalived飘一个VIP,这种方案和方案1效果类似,不过增加了负载均衡,可以分担单个apiserver的压力
外置负载均衡的方式,一般也是两台haproxy或nginx,然后使用keepalived飘一个VIP,如果是云服务器,直接购买内网负载均衡吧,免费的
apiserver地址配置成127.0. ...
openssh配置记录
优化登录速度关闭 UseDNS和GSSAPIAuthentication可以加速SSH登录, UseDNS和GSSAPIAuthentication是什么?
每次登录SSH时总是要停顿等待一下才能连接上,,这是因为OpenSSH服务器有一个DNS查找选项UseDNS默认情况下是打开的。
UseDNS 选项打开状态下,当客户端试图登录SSH服务器时,服务器端先根据客户端的IP地址进行DNS,PTR反向查询出客户端的主机名,然后根据查询出的客户端主机名进行DNS正向A记录查询,验证与其原始IP地址是否一致,这是防止客户端欺骗的一种措施,但一般我们的是动态IP不会有PTR记录,打开这个选项不过是在白白浪费时间而已,不如将其关闭。
GSSAPI ( Generic Security Services Application Programming Interface) 是一套类似Kerberos 5的通用网络安全系统接口。该接口是对各种不同的客户端服务器安全机制的封装,以消除安全接口的不同,降低编程难度。但该接口在目标机器无域名解析时会有问题
编辑配置文件 vim /etc/ssh/ssh ...
Linux的ulimit限制
临时设置
命令
说明
ulimit -a
查看所有限制值
ulimit -n 65535
临时调整open files限制值
永久设置配置文件:/etc/security/limits.conf
Ubuntu和DebianCentOS和Fedora12345678* soft nofile 65535* hard nofile 65535* hard nproc 65535* soft nproc 65535root soft nofile 65535root hard nofile 65535root hard nproc 65535root soft nproc ...
在Kubernetes集群中挂载configmap到pod中
挂载整个configmap123456789101112131415161718192021222324252627282930313233343536373839404142apiVersion: v1kind: ConfigMapmetadata: name: busybox-configmapdata: 1.txt: | 11111111111111111 2.txt: | 22222222222222222---apiVersion: apps/v1kind: Deploymentmetadata: name: busyboxspec: selector: matchLabels: app: busybox replicas: 1 template: metadata: labels: app: busybox spec: volumes: - name: busybox-volume configMap: name: busybox-configm ...
在Kubernetes集群中部署多个Nginx Ingress Controller
为什么要在集群中部署两个Nginx Ingress Controller? 因为公司的入口目前是在一个Ingress上, 公网域名也解析到了这个Ingress Controller上面,不过有些内网的服务,我们并不想让它暴露在外,那么可以再部署一个内网使用的Ingress Controller。
官方介绍地址:https://kubernetes.github.io/ingress-nginx/user-guide/multiple-ingress/
我准备将这两个ingressclass放在两个namespace里面。
先抽出clusterrole 和 clusterrolebinding因为可以使用一个clusterrole,没必要每个ingress controller都创建clusterrole
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 ...
Linux下tmp目录的管理
生成临时文件可以使用mktemp命令生成tmp文件,mktemp -d生成临时目录,避免临时目录重复使用的问题
123456#!/bin/bashtmp_file="$(mktemp)"tmp_folder="$(mktemp -d)"echo $tmp_fileecho $tmp_folder
tmp目录定时清理这个是由systemd的几个模块实现的, 在centos7中:
123systemd-tmpfiles-setup.service :Create Volatile Files and Directoriessystemd-tmpfiles-setup-dev.service:Create static device nodes in /devsystemd-tmpfiles-clean.service :Cleanup of Temporary Directories
配置文件也有3个地方:
123/etc/tmpfiles.d/*.conf/run/tmpfiles.d/*.conf/usr/lib/tmpfiles.d/*. ...
harbor接入外部trivy镜像漏洞扫描
harbor接入trivy漏洞扫描, 用到的开源工具harbor-scanner-trivy
安装需要依赖Redis, 先安装Redis
安装trivytrivy是扫描核心组件, 需要安装,参考trivy官网安装文档
https://aquasecurity.github.io/trivy/v0.41/getting-started/installation/
12345678910RELEASE_VERSION=$(grep -Po '(?<=VERSION_ID=")[0-9]' /etc/os-release)cat << EOF | sudo tee -a /etc/yum.repos.d/trivy.repo[trivy]name=Trivy repositorybaseurl=https://aquasecurity.github.io/trivy-repo/rpm/releases/$RELEASE_VERSION/\$basearch/gpgcheck=1enabled=1gpgkey=https://aquasecuri ...
python常用配置
pip升级pip版本1pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple pip -U
镜像源中科大源配置说明: https://mirrors.ustc.edu.cn/help/pypi.html
临时使用1pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple package
设为默认通过pip命令来配置通过配置文件来配置升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
1pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simplevim ~/.config/pip/pip.conf
12[global]index-url = https://mirrors.ustc.edu.cn/pypi/web/simple