"Kubernetes์ ์๋น์ค ํ์ ๋ค๊ณผ ๊ฐ๊ฐ์ ์ฉ๋์ ๋ํด ์ค๋ช ํด์ฃผ์ธ์. ๋ํ Pod ๊ฐ ํต์ ์ด ์ด๋ป๊ฒ ์ด๋ฃจ์ด์ง๋์ง ์ค๋ช ํด์ฃผ์ธ์."
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ClusterIP
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
apiVersion: v1
kind: Service
metadata:
name: my-nodeport-service
spec:
type: NodePort
selector:
app: my-app
ports:
- port: 80
targetPort: 8080
nodePort: 30007 # 30000-32767 ๋ฒ์
apiVersion: v1
kind: Service
metadata:
name: my-lb-service
spec:
type: LoadBalancer
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
externalTrafficPolicy: Local
apiVersion: v1
kind: Service
metadata:
name: my-database
spec:
type: ExternalName
externalName: database.example.com
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: api-allow
spec:
podSelector:
matchLabels:
app: api
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
role: frontend
ports:
- protocol: TCP
port: 8080
egress:
- to:
- podSelector:
matchLabels:
role: database
ports:
- protocol: TCP
port: 5432
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-external-traffic
spec:
podSelector:
matchLabels:
app: web
policyTypes:
- Ingress
ingress:
- from:
- ipBlock:
cidr: 172.17.0.0/16
except:
- 172.17.1.0/24
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: myapp.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
- path: /web
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tls-ingress
spec:
tls:
- hosts:
- myapp.example.com
secretName: tls-secret
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
-
"์๋น์ค ๋ฉ์(Service Mesh)๋ฅผ ์ฌ์ฉํด๋ณด์ จ๋์? ์ฅ๋จ์ ์ ๋ฌด์์ธ๊ฐ์?"
-
"๋ฉํฐ ํด๋ฌ์คํฐ ํ๊ฒฝ์์ ์๋น์ค ๋์ค์ปค๋ฒ๋ฆฌ๋ ์ด๋ป๊ฒ ๊ตฌํํ์๋์?"
-
"Ingress ์ปจํธ๋กค๋ฌ ์ ํ ์ ๊ณ ๋ ค์ฌํญ์ ๋ฌด์์ธ๊ฐ์?"
-
"๋คํธ์ํฌ ์ ์ฑ ์ผ๋ก ๋ง์ดํฌ๋ก์๋น์ค ๊ฐ ํต์ ์ ์ด๋ป๊ฒ ์ ์ดํ์๋์?"
# ์๋น์ค ์ฐ๊ฒฐ์ฑ ํ
์คํธ
kubectl run -i --tty --rm debug \
--image=busybox --restart=Never \
-- wget -O- http://my-service:80
# ์๋ํฌ์ธํธ ํ์ธ
kubectl get endpoints my-service
# ํธ๋ํฝ ๋ถํ ์์
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-service-split
spec:
hosts:
- my-service
http:
- route:
- destination:
host: my-service-v1
subset: v1
weight: 90
- destination:
host: my-service-v2
subset: v2
weight: 10
์ค์ ๋ฉด์ ์์๋ ์ด๋ก ์ ์ธ ์ง์๊ณผ ํจ๊ป ๋คํธ์ํฌ ๊ตฌ์ฑ ๊ฒฝํ, ํธ๋ฌ๋ธ์ํ ๊ฒฝํ, ์ฑ๋ฅ ์ต์ ํ ๊ฒฝํ ๋ฑ์ ๊ตฌ์ฒด์ ์ผ๋ก ์ค๋ช ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.