[英]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.