다음 yaml 을 deploy-nginx.yml 로 저장한다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
vagrant@slave1:~$ k apply -f deploy-nginx.yml
deployment.apps/nginx configured
vagrant@slave1:~$ k get po -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-7fd55b9958-4k7wm 2/2 Running 0 40s
nginx-7fd55b9958-fxmbz 2/2 Running 0 54s
vagrant@slave1:~$ k exec -it nginx-7fd55b9958-4k7wm -- curl localhost
error: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "50c3389b65646a4707e90732ae67621d11af7559cb68ce952ac8e821cb9ded74": OCI runtime exec failed: exec failed: unable to start container process: exec: "curl": executable file not found in $PATH: unknown
버전 확인
root@nginx-7fd55b9958-4k7wm:/# nginx -v
nginx version: nginx/1.14.2
html 루트 위치 확인
root@nginx-7fd55b9958-4k7wm:/# cd /usr/share/nginx/html
root@nginx-7fd55b9958-4k7wm:/usr/share/nginx/html# ls
50x.html index.html
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
run: nginx
spec:
ports:
- port: 80
protocol: TCP
selector:
run: nginx
vagrant@slave1:~$ k apply -f svc-nginx.yml
service/nginx configured
// 서비스 리소스 확인
vagrant@slave1:~$ k get svc -l run=nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx ClusterIP 10.100.12.202 <none> 80/TCP 24h
// 비지박스로 DNS 확인 및 wget으로 서비스 포트 접근 확인
vagrant@slave1:~$ k run curl --image=radial/busyboxplus:curl -i --tty
If you don't see a command prompt, try pressing enter.
[ root@curl:/ ]$ nslookup nginx
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: nginx
Address 1: 10.100.12.202 nginx.default.svc.cluster.local
[ root@curl:/ ]$ wget -qO- http://nginx:80
<!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>
// 엔드포인트 확인
vagrant@slave1:~$ kubectl get endpoints nginx
NAME ENDPOINTS AGE
nginx 192.168.140.81:80 24h