K8S安装openresty

前言

之前绍过原生安装openresty 详见文档OpenResty的安装 ,本文主要介绍基于k8s的安装。

docker官方推荐镜像:https://hub.docker.com/r/bitnami/openresty

此镜像不包含zlib.so库,无法通过Lua进行gzip的解压,所以我们需要手动编译openresty

安装教程

  1. 准备docker仓库

(1)注册docker账户或者搭建私有docker仓库

docker官网:https://hub.docker.com

*这里我们使用官方docker仓库,注册过程省略

(2)创建仓库

示例:305467425/openresty-gm

2、安装docker

选择一台k8s主机:172.19.230.201

过程省略,参考centos7 安装docker

3、创建Dockerfile

k8s主机执行:

mkdir -p /usr/local/gm-openresty
vim Dockerfile

Dockerfile内容:

FROM centos:7

WORKDIR  /usr/local/gm-openresty
# 安装所需依赖包
RUN yum -y install perl make gcc gcc-c++ libstdc++-devel pcre-devel zlib-devel net-tools pcre wget && \
yum clean all && \
wget https://openresty.org/download/openresty-1.19.3.1.tar.gz && tar xzfm openresty-1.19.3.1.tar.gz && \
ln -s /usr/lib64/libpcre.so.1 /usr/lib64/libpcre.so.3

RUN yum -y install openssl openssl-devel && \
cd openresty-1.19.3.1/ && \
./configure --prefix=/usr/local/openresty \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-file-aio \
--with-ld-opt="-lm"  && \
make install && \
rm -rf /usr/local/gm-openresty/* && \
ln -sf /dev/stdout /usr/local/openresty/nginx/logs/std_access.log && \
ln -sf /dev/stderr /usr/local/openresty/nginx/logs/std_error.log && \
ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/bin/openresty 


# Add zlib.so
RUN yum -y install cmake automake zlib unzip && \
cd /usr/local/openresty/ && \
wget https://github.com/brimworks/lua-zlib/archive/master.zip && unzip master.zip
wget https://github.com/brimworks/lua-zlib/archive/master.zip && unzip master.zip && \
# /usr/share/cmake/Modules  FindLua51.cmake,cp为FindLua.cmake
\cp /usr/share/cmake/Modules/FindLua51.cmake /usr/share/cmake/Modules/FindLua.cmake && \
cd /usr/local/openresty/lua-zlib-master && \
cmake -DLUA_INCLUDE_DIR=/usr/local/openresty/luajit/include/luajit-2.1 && \
make && \
cp zlib.so /usr/local/openresty/lualib/zlib.so

# Add additional binaries into PATH for convenience
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin

EXPOSE 80 443
CMD ["/usr/bin/openresty", "-g", "daemon off;"]

# Use SIGQUIT instead of default SIGTERM to cleanly drain requests
# See https://github.com/openresty/docker-openresty/blob/master/README.md#tips--pitfalls
STOPSIGNAL SIGQUIT

更新20221207:github被墙了,可能无法下载了,想办法下载了自己上传吧

注:lua-zlib-master.zip的原始下载地址为github,网络不能够访问的情况下,28行可以替换为minio地址,此地址当前只能内网访问

wget http://172.19.230.201:30090/nj-track/lua-zlib-master.zip && unzip lua-zlib-master.zip && \

4、执行编译

docker login -u 305467425
docker build -t 305467425/openresty-gm:v1.0.5 .
#docker tag openresty-gm 305467425/openresty-gm:v1.0.5
docker push 305467425/openresty-gm:v1.0.5

5、k8s部署

参考:

 
---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations: {}
  labels:
    app: openresty-deployment
    k8s.kuboard.cn/name: openresty-deployment
    version: 1.0.1
  name: openresty-deployment
  namespace: nginx
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
        version: 1.0.1
      name: nginx
    spec:
      containers:
        - image: '305467425/openresty-gm:v1.0.5'
          imagePullPolicy: IfNotPresent
          name: nginx
          ports:
            - containerPort: 8080
              protocol: TCP
            - containerPort: 80
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30

附录

常用的Nginx http功能模块有哪些?

ngx_http_core_module 包括一些核心的http参数配置,对应Nginx的配置为HTTP区块部分

ngx_http_access_module 访问控制模块,用来控制网站用户对Nginx的访问

ngx_http_gzip_module 压缩模块,对Nginx返回的数据压缩,属于性能优化模块

ngx_http_fastcgimodule FastCGI模块,和动态应用相关的模块,例如PHP

ngx_http_proxy_module proxy代理模块

ngx_http_upstream_module 负载均衡模块,可以实现网站的负载均衡功能及节点的健康检查

ngx_http_rewrite_module URL地址重写模块

ngx_http_limit_conn_module 限制用户并发连接数及请求数模块

ngx_http_limit_req_module 根据定义的key限制Nginx请求过程的速率

ngx_http_log_module 访问日志模块,以指定的格式记录Nginx客户访问日志等信息

ngx_http_auth_basic_module Web认证模块,设置Web用户通过账号、密码访问Nginx

ngx_http_ssl_module ssl模块,用于加密的http连接,如https

ngx_http_stub_status_module 记录Nginx基本访问状态信息等的模块

参考链接

https://developer.aliyun.com/article/785336

https://www.cnblogs.com/Hi-blog/p/How-To-Compile-OpenResty-From-Source-Code.html

centos7 安装docker

OpenResty的安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值