使用 Dockerfile 构建镜像注意事项

面试问 Dockerfile 的优化, 千万不要只会说减少层数 在面试的时候, 我通常都会问「如果优化 Dockerfile」? 面试的朋友大部分都会说 使用更小的基础镜像, 比如 alpine. 减少镜像层数, 使用 && 符号将命令链接起来。 好一点的面试者 我会给基础镜像打上 安全补丁。 但这些都没说到点上。 优化 Dockerfile 的核心是 合理分层。 为什么要……

阅读全文

golang-use-regex-group

golang 使用 regex group 的值 与常用的语言正则不同, golang 使用 $1 表示 regex group。 而类似 sed, python 中常用的是 \1 golang playgroud 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 package main import ( "fmt" "regexp" ) func main() { re := regexp.MustCompile(`([A-Z])`) s := re.ReplaceAllString("UserCreate", ".$1") fmt.Println(s) // .User.Create } func Test_Regexp(t *testing.T) { chars := `('|")` str := `"123'abc'456"` re := regexp.MustCompile(chars) s := re.ReplaceAllString(str, `\$1`) // 这里可以使用 ` 反引号 fmt.Println(s) // \"123\'abc\'456\" } // https://stackoverflow.com/questions/43586091/how-golang-replace-string-by-regex-group python 1 2 3 import re name = re.sub(r'([A-Z])', r'.\1', "UserCreate") print(name) # .User.Create……

阅读全文

K8S 中使用 Heketi 管理 GlusterFS

K8S 中使用 Heketi 管理 GlusterFS 与 官方文档不同 , 本文中的 glusterfs 是独立与 k8s 之外的。 Heketi heketi 项目 为 GlusterFS 提供 RESTful 的 API 管理。 Requirements System must have glusterd service enabled and glusterfs-server installed Disks registered with Heketi must be in raw format. 目前提供两种管理方式: ssh, kubernetes heketi-ssh SSH Access SSH user and public key already setup on the node SSH user must have password-less sudo Must be able to run sudo commands from ssh. This requires disabling requiretty in the /etc/sudoers file 使用容器部署 https://hub.docker.com/r/heketi/heketi/ heketi-kubernetes 带实现 勘误 在使用 K8S 部署时, 如果客户端报错……

阅读全文

K8S节点下载 gcr.io 原生镜像

K8S下载 gcr.io 原生镜像 在国内是不能直接下载 gcr.io / k8s.gcr.io 等原生镜像的。 使用比较权威的三方源 aliyun , qcloud 将 gcr.io push 到 hub.docker.com 自建镜像代理 域名翻墙 域名翻墙 通过域名劫持,将目标地址直接解析到代理服务器上。 sniproxy 所有你需要的, 一个能直接访问 gcr.ip 的 https(443) 代理。 通过 sniproxy 实现。 通过 防火墙 , 安全组 限制访问来源。 1 2 # docker run -d --rm --network host --name sniproxy……

阅读全文

docker multi-stage build

Docker multi-stage build Multi-stage 构建,最大的好处是 Docker 本身在构建过程中提供了一个缓存空间,将上一个 stage 的结果通过 COPY --from=<stage> 复制到下一个 stage。 这样就大大简化了镜像清理工作。 这里, docker 官方文档已经对 Multi-stage build 已经有详细说明了。 multi-stage 要求 docker version >= 17.05 举例 每一个 FROM 关键字都表示此处是一个 stage 对 stage 使用命令的关键字是 as , 例如 FROM alpine:latest as initer 在引用……

阅读全文

Haproxy反向代理FTP

Haproxy 反向代理 FTP 4层 代理 haproxy-1.5.18-7.el7.x86_64 #--------------------------------------------------------------------- # Example configuration for a possible web application. See the # full configuration options online. # # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt # #--------------------------------------------------------------------- #--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user root group root daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections……

阅读全文

k8s node 节点

k8s node 节点介绍 node 是 k8s 的工作节点, cpu, memory 的提供者。 上面运行这实际工作的 pod。 node 的服务包括 container 环境、 kubelet 和 kube-proxy。 使用 kubectl 管理 node 基础语法为 : kubectl flag node <node_name> kubectl cordon / uncordon 1 2 3 4 # 驱逐 kubectl cordon node <node_name> # 恢复 kubectl uncordon node <node_name>……

阅读全文

filebeat将多行日志视作一样的参数配置

filebeat 将多行日志视作一样的参数配置 在 filebeat 格式化日志是,可以配置 pattern 将多行日志合并成一样。 在配置文件 filebeat.yml 中,协同完成这个功能的参数有 4 个。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 # The regexp Pattern that has to be matched. # 设置行的匹配字段 multiline.pattern: '^[[:space:]]|^[[:alpha:]]' # Defines if the pattern set under pattern should be negated or not. Default is false. # 设置符合上面匹配条件的的行,是否应该被合……

阅读全文

Linux 下的几个命令行下载工具

Linux 下的几个命令行下载工具 linux 下最常用的 wget 是单线程的。虽然好用,但不够用。例如在下载阿里云的数据库备份文件,单线程最多能达到 10Mbps,即使是走内网。 因此,有必要换一下其他的。 axel https://github.com/axel-download-accelerator/axel axel 相较 wget 最大的优点就是支持多线程。 在 ubuntu 16.04 LST 上安装非常简单,已经加入了官方源。 CentOS 系列的话,就去 pkgs.org 上找到对……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它