[英]Apache web server custom index kubernetes
我使用来自 dockerhub 的标准 httpd 映像在 kubernetes 集群上部署了 apache web 服务器。 我想对索引文件进行更改,以便它打印容器 ID 而不是默认索引文件。 我怎样才能做到这一点?
回答问题:
How can I have a
Apache
container in Kubernetes that will output the id of the container in theindex.html
or other.html
file.
处理它的一种方法是通过lifecycle hooks
(特别是postStart
):
PostStart
这个钩子在容器创建后立即执行。 但是,不能保证钩子会在容器 ENTRYPOINT 之前执行。 没有参数传递给处理程序。
至于如何实现设置的示例:
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache
labels:
app: apache
spec:
replicas: 3
selector:
matchLabels:
app: apache
template:
metadata:
labels:
app: apache
spec:
containers:
- name: apache
image: httpd # <-- APACHE IMAGE
# LIFECYCLE DEFINITION START
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo $HOSTNAME > htdocs/hostname.html"]
# LIFECYCLE DEFINITION END
ports:
- containerPort: 80
具体来看:
command: ["/bin/sh", "-c", "echo $HOSTNAME > htdocs/hostname.html"]
这部分会将容器的hostname.html
名写入/保存到主机名。html
要检查每个Pod
是否具有hostname.html
,您可以创建一个Service
并运行:
$ kubectl port-forward svc/apache 8080:80
-> curl localhost:8080/hostname.html
$ kubectl run -it --rm nginx --image=nginx -- /bin/bash
-> curl apache/hostname.html
其他资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.