nginx POD container /usr/share/nginx/html/index.html
nginx 컨테이너를 replicas로 1개 이상 만들 경우 각 nginx 파일을 구분하기 위해서, index.html를 수정
[1]. nginx container index html 파일 위치
/usr/share/nginx/html/index.html
[2]. nginx 컨테이너 접근
# kubectl exec -it pod/nginx-pod -n default -- bin/bash
[3]. index.html 파일 수정
replicas로 1개 이상 만들 경우 각 nginx 파일을 구분하기 위해서, index.html를 수정
root@nginx-pod:/usr/share/nginx/html# cat ./index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@nginx-pod:/usr/share/nginx/html#
root@nginx-pod:/usr/share/nginx/html# echo "----------------------" >> ./index.html
root@nginx-pod:/usr/share/nginx/html# echo "---------TEST---------" >> ./index.html
root@nginx-pod:/usr/share/nginx/html# echo "----------------------" >> ./index.html
root@nginx-pod:/usr/share/nginx/html#
root@nginx-pod:/usr/share/nginx/html# cat ./index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
----------------------
---------TEST---------
----------------------
root@nginx-pod:/usr/share/nginx/html# exit
exit
#
# exit
[root@kubernetes ~]#
[4]. nginx 를 nodeport로 서비스를 open 해서 curl로 확인
[root@kubernetes ~]# curl 192.168.0.60:30762
[5]. nginx Deployment,Service YAML with NodePort
---
apiVersion: v1
kind: Service
metadata:
name: nginx-pod-service
namespace: default
spec:
type: NodePort
selector:
apps: webserverpod
ports:
- name: http
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-pod
namespace: default
labels:
apps: webserverpod
spec:
replicas: 3
selector:
matchLabels:
apps: webserverpod
template:
metadata:
labels:
apps: webserverpod
spec:
serviceAccount: default
securityContext:
runAsUser: 0
dnsPolicy: "None"
dnsConfig:
nameservers:
- 8.8.8.8
containers:
- name: nginx-pod
image: docker.io/library/nginx:stable
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
protocol: TCP
resources:
limits:
memory: "800Mi"
cpu: "800m"
requests:
memory: "600Mi"
cpu: "400m"
terminationGracePeriodSeconds: 10
---
nginx POD,Service YAML with NodePort
apiVersion: v1
kind: Service
metadata:
name: nginx-pod
namespace: default
spec:
ports:
- name: web-port
port: 80
selector:
app: webserverpod
type: NodePort
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
namespace: default
labels:
app: webserverpod
spec:
containers:
- name: my-webserver
image: localhost/nginx:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
securityContext: { privileged: true }
nodeSelector:
kubernetes.io/hostname: kubernetes-worker01