Skip to main content

04B. Nginx ์„œ๋น„์Šค

Less than 1 minuteKubernetescrashcoursedigitaloceankubernetesminkubekubctl

04B. Nginx ์„œ๋น„์Šค ๊ด€๋ จ

๋ชฉ์ฐจ

์–ธ์ œ๋‚˜ ์ตœ์‹  Kubernetes

Unit 4. Nginx YAML ์„ค์ • ํŒŒ์ผ ์ž‘์„ฑํ•˜๊ธฐ

์–ธ์ œ๋‚˜ ์ตœ์‹  Kubernetes

์ด๋ฒˆ์—๋Š” ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ๋‚ด์šฉ์„ service.yaml ํŒŒ์ผ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

jHLsKubernetes/Unit04/service.yaml at main ยท pyrasis/jHLsKubernetes

...
service.yaml
apiVersion: v1
kind: Service
metadata:
  name: hello-nginx
spec:
  selector:
    app: hello-nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP

๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ service.yaml ํŒŒ์ผ๋กœ ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

kubectl create -f service.yaml
#
# service/hello-nginx created

๊ทธ๋Ÿผ kubectl์˜ port-forward ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด์„œ ์„œ๋น„์Šค์— ์ ‘๊ทผํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

kubectl port-forward service/hello-nginx 8000:80
# 
# Forwarding from 127.0.0.1:8000 -> 80
# Forwarding from [::1]:8000 -> 80
Nginx ์„œ๋น„์Šค์™€ ๋””ํ”Œ๋กœ์ด๋จผํŠธ
Nginx ์„œ๋น„์Šค์™€ ๋””ํ”Œ๋กœ์ด๋จผํŠธ

์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์—ด๊ณ  [http://127.0.0.1:8000]์— ์ ‘์†ํ•˜๋ฉด **Welcome to nginx!**๊ฐ€ ํ‘œ์‹œ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋””ํ”Œ๋กœ์ด๋จผํŠธ์™€ ์„œ๋น„์Šค ์‚ญ์ œ

๋””ํ”Œ๋กœ์ด๋จผํŠธ์™€ ์„œ๋น„์Šค๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด kubectl delete -f ๋ช…๋ น์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

kubectl delete -f deployment.yaml
kubectl delete -f service.yaml

๋””ํ”Œ๋กœ์ด๋จผํŠธ์™€ ์„œ๋น„์Šค ์„ค์ • ๋ณ€๊ฒฝ

.deployment.yaml ํŒŒ์ผ๊ณผ service.yaml ํŒŒ์ผ์„ ์ˆ˜์ •ํ•œ ๋’ค ๋ณ€๊ฒฝ๋œ ์„ค์ •์„ ์ ์šฉํ•˜๋ ค๋ฉด kubectl apply -f ๋ช…๋ น์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

์ด์ฐฌํฌ (MarkiiimarK)
Never Stop Learning.