Switching Routing
ip link
์๋ก ๋ค๋ฅธ Host ๊ฐ ํต์ ํ๊ธฐ ์ํด์ ๋ Host ๋ฅผ ์ด์ด์ฃผ๋ Switch ๊ฐ ํ์ํ๋ค. Host ๋ฅผ Switch ์ ์ฐ๊ฒฐํ๋ ค๋ฉด Network Interface ๊ฐ ํ์ํ๋ฐ, ์ ๋ช
๋ น์ด๋ฅผ ํตํด Host ์ Network Interface ๋ฅผ ํ์ธํ ์ ์๋ค. Linux ์ ๊ฒฝ์ฐ eth0
๋ผ๋ Network Interface ๋ฅผ ํ์ธํ ์ ์๋ค.
ip addr
ip addr add 192.168.1.10/24 dev eth0
Host ๋ค์ด Switch ์ ์ฐ๊ฒฐ๋ ์ดํ ์ ๋ช ๋ น์ด๋ฅผ ํตํด Host ์ IP ์ฃผ์๋ฅผ ํ ๋นํด์ค ์ ์๋ค.
ip route
ip route add 192.168.2.0/24 via 192.168.1.1
ip route add default via 192.168.2.1
ip route add 0.0.0.0 via 192.168.2.1
์๋ก ๋ค๋ฅธ Switch ๊ฐ ํต์ ํ๊ธฐ ์ํด์ ๋ Switch ๋ฅผ ์ด์ด์ฃผ๋ Router ๊ฐ ํ์ํ๋ค. 192.168.2.0/24
์ ์ฃผ์๋ฅผ ๊ฐ์ง๋ Switch ์ ์ ๊ทผํ๊ธฐ ์ํด์ Router ์ 192.168.1.1
์ฃผ์๋ฅผ ๊ฑฐ์ณ๊ฐ๋ฉด ๋๋ค๋ ์๋ฏธ๋ค. default
๋๋ 0.0.0.0
๋ ์ด์ธ ๋ชจ๋ ์ฃผ์๋ฅผ ์๋ฏธํ๋ฉฐ ์ฆ, ์ธํฐ๋ท์ ์ ๊ทผํ๊ธฐ ์ํด์ 192.168.2.1
์ฃผ์๋ฅผ ๊ฑฐ์ณ๊ฐ์ผ ๋๋ค๋ ์๋ฏธ๋ค.
cat /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward
Router ๊ฐ 192.168.1.1
์ 192.168.2.1
์ ์ฃผ์๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ ๊ฒ์ eth0
๊ณผ eth1
์ด ํ ๋น๋๋ค๋ ์๋ฏธ์ด๊ณ , ๊ธฐ๋ณธ์ ์ผ๋ก ์๋ก ๋ค๋ฅธ Network Interface ๊ฐ์ Packet ์ ๋ฌ์ ๋งํ์๋ค. ์ ๋ช
๋ น์ด๋ฅผ ํตํด ip_forward
๊ฐ์ 1 ๋ก ๋ฐ๊ฟ์ฃผ๋ฉด Router ๋ด๋ถ์์ Packet ๋ฅผ Network Interface ๊ฐ์ ์ ๋ฌํ ์ ์๋๋ก ํด์ค ์ ์๋ค. ์ฌ๋ถํ
ํ ๊ฒฝ์ฐ ์ค์ ๊ฐ์ด ์ด๊ธฐํ ๋๊ธฐ ๋๋ฌธ์ /etc/sysctl.conf
์์ net.ipv4.ip_forward
๊ฐ์ 1 ๋ก ์ค์ ํด์ฃผ๋ฉด ์๊ตฌ์ ์ผ๋ก ์ค์ ํ ์๋ ์๋ค.
DNS
cat /etc/hosts
IP ์ฃผ์ ๋์ Name ์ผ๋ก Host ๋ฅผ ์๋ณํ๊ธฐ ์ํด ์ ๊ฒฝ๋ก์ IP ์ฃผ์์ ํด๋นํ๋ Host Name ์ ์ง์ ํด ์ค ์ ์๋ค. ๋์ ๋ชจ๋ Host ์ ํ์ํ๊ธฐ ๋๋ฌธ์ ๊ด๋ฆฌํ๊ธฐ๊ฐ ์ด๋ ค์์ง๋ค. ๋๋ฌธ์ DNS ์๋ฒ๋ฅผ ํ์ฉํด ํ๋์ ๊ด๋ฆฌํฌ์ธํธ๋ก ํตํฉํ๋ค.
cat /etc/resolv.conf
DNS ์๋ฒ์ ์ฃผ์๋ ์ ๊ฒฝ๋ก์ ์ ์ฅํ์ฌ ์ฌ์ฉํ ์ ์๋ค. 8.8.8.8
์ Google ์ด ์ ๊ณตํ๋ DNS ์๋ฒ๋ค.
cat /etc/nsswitch.conf
...
hosts: files dns
...
๊ธฐ๋ณธ์ ์ผ๋ก /etc/hosts
์์ ์ฃผ์๋ฅผ ์ฐพ๊ณ ์์ผ๋ฉด /etc/resolv.conf
์์ ์ฃผ์๋ฅผ ์ฐพ๋๋ฐ, ์ ์ค์ ํ์ผ์์ ์์๋ฅผ ๋ณ๊ฒฝํ ์๋ ์๋ค.
CoreDNS
wget https://github.com/coredns/coredns/releases/download/v1.7.0/coredns_1.7.0_linux_amd64.tgz
cat > /etc/hosts
192.168.1.10 web
192.168.1.11 db
192.168.1.15 web-1
192.168.1.16 db-1
192.168.1.21 web-2
192.168.1.22 db-2
DNS ์๋ฒ๋ฅผ ๊ตฌ์ถํ๋ ค๋ฉด DNS ์ํํธ์จ์ด๊ฐ ์ค์น๋ Host ๊ฐ ํ์ํ๋ค. CoreDNS ๋ผ๋ DNS ์ํํธ์จ์ด๋ฅผ ์ค์นํ์ฌ DNS ์๋ฒ๋ฅผ ๊ตฌ์ถํ ์ ์๋ค.
Network Namespaces
ip netns add red
ip netns add blue
Container ๊ฐ namespace ๋ฅผ ํตํด ํ๋ก์ธ์ค๋ฅผ ๊ฒฉ๋ฆฌํ๋ฏ Network ์ญ์ ๊ฒฉ๋ฆฌํ ์ ์๋ค. ์ ๋ช
๋ น์ด๋ red
์ blue
๋ผ๋ ์ด๋ฆ์ ๊ฐ์ง Network Namespace ๋ฅผ ์์ฑํ๋ค๋ ์๋ฏธ๋ค.
ip netns exec red ip link
ip -n red link
ip link
๋ช
๋ น์ด๋ฅผ ํตํด Network Interface ๋ฅผ ํ์ธํ๋ฏ Network Namespace ์ Network Interface ๋ฅผ ํ์ธํ๊ธฐ ์ํด์ ์ ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
ip -n red arp
ip -n red route
arp ์ route ์ญ์ ๋์ผํ ๋ฐฉ๋ฒ์ผ๋ก ํ์ธํ ์ ์๋ค.
Virtual Cable
ip link add veth-red type veth peer name veth-blue
์ ๋ช ๋ น์ด๋ก ๊ฐ์ ์ผ์ด๋ธ์ ์์ฑํ๊ณ ,
ip link set veth-red netns red
ip link set veth-blue netns blue
ip -n red addr add 192.168.15.1/24 dev veth-red
ip -n blue addr add 192.168.15.2/24 dev veth-blue
ip -n red link set veth-red up
ip -n blue link set veth-blue up
์ ๋ช ๋ น์ด๋ก Network Namespace ๋ผ๋ฆฌ ์ฐ๊ฒฐํด์ค ์ ์๋ค.
Linux Bridge
ip link add v-net-0 type bridge
ip link set dev v-net-0 up
Network Namespace ๊ฐ ๋ง์์ง ๊ฒฝ์ฐ Switch ์ญํ ์ ํ๋ Linux Bridge ๋ฅผ ํ์ฉํ ์ ์๋ค.
ip link add veth-red type veth peer name veth-red-br
ip link set veth-red netns red
ip link set veth-red-br master v-net-0
ip -n red addr add 192.168.15.1 dev veth-red
ip -n red link set veth-red up
์ดํ Network Namespace ์ Bridge ๋ฅผ ์ฐ๊ฒฐํ๊ธฐ ์ํ Virtual Cable ์ ์์ฑ ๋ฐ ํ ๋นํด์ฃผ๊ณ , IP ์ฃผ์ ๋ ํ ๋นํด ์ค ๋ค ํ์ฑํ ํด์ฃผ์.
ip addr add 192.168.15.5/24 dev v-net-0
์ ๋ช ๋ น์ด๋ฅผ ํตํด Host ์ Bridge ๋ฅผ ์ฐ๊ฒฐํด์ฃผ์.
ip netns exec blue ip route add 192.168.1.0/24 via 192.168.15.5
Namespace ๊ฐ ์ธ๋ถ Host ์ ํต์ ํ๊ธฐ ์ํด์ ์ธ๋ถ์ 192.168.1.0/24
์ ์ฃผ์๋ฅผ ๊ฐ์ง๋ Switch ์ routing ์ค์ ์ ํด์ค์ผํ๋ค. ์ ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด 192.168.15.5
์ ์ฃผ์๋ฅผ ๊ฐ์ง๋ v-net-0
์ ํตํด ํธ์คํธ์ eth0
๋ฅผ ๊ฑฐ์ณ ์ธ๋ถ๋ก ํฅํ๊ฒ ๋๋ค.
iptables -t nat -A PREROUTING --dport 80 --to-destination 192.168.15.2:80 -j DNAT
์ธ๋ถ Host ๊ฐ ๋ค๋ฅธ Host ์ Network Namespace ์ ์ ๊ทผํ๊ธฐ ์ํด์ ์ ๋ช ๋ น์ด๋ก ํฌํธํฌ์๋ฉ ํด์ค์ผ ํ๋ค.
Docker Networking
ip link
08. Docker Networking ์์ ๋ฐฐ์ด bridge ๊ฐ ๋ฐ๋ก Linux Bridge ๋ค. ip link
๋ก ํ์ธํด๋ณด๋ฉด docker0
๋ผ๋ ์ด๋ฆ์ ๊ฐ์ง Network Interface ๋ฅผ ํ์ธํ ์ ์๋ค.
ip netns
Docker Container ๋ฅผ ์คํํ๋ฉด Network Namespace ๋ ๋ง์ฐฌ๊ฐ์ง๋ก ์๋์ผ๋ก ์์ฑ๋๋ค.
iptables -nvL -t nat
ํฌํธํฌ์๋ฉ๋ ๋ง์ฐฌ๊ฐ์ง. Docker Container ๋ฅผ ์คํํ ๋ iptable
์ค์ ๊น์ง ์๋์ผ๋ก ์์ฑ๋๋ค.
์ฆ, Docker Container ๋ฅผ ์์ฑํ ๋, ๋คํธ์ํฌ ์ธก๋ฉด์์ ๋ด๋ถ์ ์ผ๋ก ์์์ ์ธ๊ธํ ๋ชจ๋ ์์ ๋ค์ด ์๋์ผ๋ก ์ํ๋๋ ๊ฒ์ด๋คโฆ
CNI
ls /opt/cni/bin/
CNI ๋ฅผ ๊ธฐ์ค์ผ๋ก Networking ๊ธฐ๋ฅ์ ๊ตฌํํ์ฌ ๊ธฐ๋ณธ์ ์ธ ๋์๊ณผ ํ๋ฌ๊ทธ์ธ๋ฑ์ ํ์ฉํ ์ ์๋ค. Docker ์ ๊ฒฝ์ฐ ๋ฐ๋ก CNM ์ด๋ผ๋ ๊ธฐ์ค์ผ๋ก CNI ๋ฅผ ๋ฐ๋ฅด์ง ์๊ธฐ ๋๋ฌธ์ K8s ๋ Docker Container ๋ฅผ None ์ผ๋ก ์์ฑํ ๋ค ์ง์ Bridge ์ ํ ๋นํ๋ ์์ ์ ๋ฐ๋ก ์ํํ๋ค.
Cluster Networking
K8s ๋ ๊ฒฐ๊ตญ Master ์ Worker Node ๊ฐ์ ํต์ ์ด ๊ฐ๋ฅํด์ผ ํจ์ผ๋ก ๊ฐ Component ๋ง๋ค ์์ ๊ฐ์ Port ๋ค์ ์ด์ด์ค์ผ ํ๋ค. ์์ธํ ๋ด์ฉ์ ๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์.
Pod Networking
์๋ก ๋ค๋ฅธ Node ์ ์์นํ Pod ๊ฐ ํต์ ์ ํ์ฑํ ํ๊ธฐ ์ํด์ ์๋์ ๊ฐ์ ์์ ์ด ํ์ํ๋ค.
ip link add v-net-0 type bridge
ip link set dev v-net-0 up
ip addr add 10.244.1.1/24 dev v-net-0
๋จผ์ ๊ฐ Node ๋ง๋ค Bridge ๋ฅผ ์์ฑํด์ค ๋ค,
ip route add 10.244.2.2 via 192.168.1.12
๋ค๋ฅธ Node ์ Bridge ๋ก ํฅํ๋ Route ๋ฅผ ์ค์ ํด์ค๋ค. ํน์ ๋ผ์ฐํฐ๋ฅผ ํ์ฉํด Routing ์ค์ ์ ํ ๊ณณ์์ ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ๋ ์๊ฒ ๋ค.
Container ๊ฐ ์์ฑ๋ ๋ ๋ง๋ค Node ์ ํ๋ํ๋ ์ ์ํด์ ์ ๋ช ๋ น์ด๋ค์ ์คํํด์ผํ๋ค. Node ๊ฐ ๋ง์์ง๊ณ ๋คํธ์ํน์ด ๋ณต์กํด์ง๋ฉด ํด๋น ์์ ์ด ๋ฒ๊ฑฐ๋ก์์ง๊ธฐ ๋๋ฌธ์ ์๋ํ๋ ์คํฌ๋ฆฝํธ๋ฅผ ํ์ฉํ ์ ์๋ค.
# net-script.sh
ADD)
# Create veth pair
# Attach veth pair
# Assign IP Address
# Bring Up Interface
DEL)
# Delete veth pair
์์ ๊ฐ์ ๊ธฐ์ค์ผ๋ก ์์ฑ๋ ์คํฌ๋ฆฝํธ๋ฅผ ํ์ฉํด Container ๊ฐ ์์ฑ๋ ๋ ๋ง๋ค ์คํํด์ฃผ๋ฉด Pod ๊ฐ ๋คํธ์ํน์ ์๋ํํ ์ ์๋ค. ์ ๊ธฐ์ค์ CNI ๊ฐ ์ ๊ณตํ๊ณ ๋ค์ํ CNI Plugin ๋ค์ด ๊ตฌํ๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ ๊ณตํ๋ค.
CNI in K8s
K8s ๋ ๊ธฐ๋ณธ์ ์ผ๋ก Pod ๊ฐ์ ํต์ ์ ์ง์ํ์ง ์๋๋ค. ๋๋ฌธ์ Pod ๊ฐ ํต์ ์ด ๊ฐ๋ฅํ๋๋ก ํ๋ ค๋ฉด CNI Plugin ์ ์ถ๊ฐ์ ์ผ๋ก ์ค์นํด ์ฌ์ฉํด์ผํ๋ค.
ExecStart=/usr/local/bin/kubelet \
...
--network-plugin=cni \
--cni-bin-dir=/opt/cni/bin \
--cni-conf-dir=/etc/cni/net.d \
...
CNI ๋ฅผ ์ค์ ํด์ฃผ๊ธฐ ์ํด์ kubelet ์ ์คํํ ๋ ์ต์ ์ผ๋ก ๋๊ฒจ์ฃผ๋ฉด๋๋ค.
ls /opt/cni/bin
์ ๊ฒฝ๋ก์์ ์ฌ์ฉํ ์ ์๋ ๋ชจ๋ CNI Plugin ๋ค์ ํ์ธํ ์ ์๋ค.
ls /etc/cni/net.d
์ ๊ฒฝ๋ก์ ์กด์ฌํ๋ ํ์ผ์ ๋ฐํ์ผ๋ก CNI Plugin ๋ฅผ ์ค์ ํ ์ ์๋ค.
cat /etc/cni/net.d/10-flannel.conflist
{
"name": "cbr0",
"cniVersion": "0.3.1",
"plugins": [
{
"type": "flannel",
"delegate": {
"hairpinMode": true,
"isDefaultGateway": true
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}
CNI weave
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
Weave ๋ CNI Plugin ์ค ํ๋์ธ ์๋ฃจ์ ์ผ๋ก ์์ ๊ฐ์ด Pod ๋ก ์์ฑํด์ ์ด์ํ ์ ์๋ค.
IP Address Management - Weave
cat /etc/cni/net.d/net-script.conflist
{
"cniVersion": "0.2.0",
"name": "mynet",
"type": "net-script",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"subnet": "10.244.0.0/16",
"routes": [
{
"dst": "0.0.0.0/0"
}
]
}
}
Pod ๊ฐ ํ ๋น๋๋ IP ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด CNI ์์ DHCP
์ host-local
์ด๋ผ๋ ๋นํธ์ธ ํ๋ฌ๊ทธ์ธ์ ์ ๊ณตํ๋ค. ํด๋น ์ค์ ์ญ์ ์ ํ์ผ์์ ๊ด๋ฆฌํ ์ ์๋ค.
Service Networking
K8s ์์ Pod ๋ผ๋ฆฌ ํต์ ํ๋ ๋์ Service Object ๋ฅผ ํตํด Cluster ๋ด Pod ๊ฐ์ ํต์ ๋๋ ์ธ๋ถ์์ ํต์ ์ ์ ๊ณตํ๋ค. Pod ์ด namespace ๋ฑ์ ํ ๋น ๋ฐ์ ์ค์ ๋ก ์กด์ฌํ๋ ๊ฒ๊ณผ ๋ฌ๋ฆฌ, Service ๋ kube-proxy ์ ์ํดCluster ์ ๊ฑธ์ณ Forwarding Rule ์ ๊ฐ์ง๊ณ ์์ฑ๋๋ Virtual Object ๋ค.
kube-proxy --proxy-mode [ userspace | iptables | ipvs ]
kube-proxy ๋ฅผ ์คํํ ๋ proxy-mode ์ต์ ์ ํตํด Forwarding Rule ์ ๊ด๋ฆฌํ ๋ฒ์ ์ ์ค์ ํ ์ ์๋ค.
kube-api-server --service-cluster-ip-range ipNet (Default: 10.0.0.0/24)
kube-api-server ๋ฅผ ์คํํ ๋ Service ๊ฐ ๊ฐ์ง ์ ์๋ IP range ๋ฅผ ์ง์ ํด์ค ์ ์๋ค. Service IP range ์ Pod IP range ๋ ๊ฒน์น๋ฉด ์๋๋ค๋ ๊ฒ๋ ์ฐธ๊ณ ํ์.
iptables -L -t nat | grep db-service
iptables ๋ชจ๋๋ก ์์ฑํ Service ์ Forwarding Rule ์ ์ ๋ช ๋ น์ด๋ฅผ ํตํด ํ์ธํ ์ ์๋ค.
DNS in K8s
<POD-IP-ADDRESS>.<namespace-name>.pod.cluster.local
<service-name>.<namespace-name>.svc.cluster.local
K8s ์์ Pod ๊ณผ Service ๋ ์ ๊ท์น์ ๋ฐ๋ผ Domain Name ์ ํ ๋น ๋ฐ๋๋ค.
CoreDNS in K8s
Pod ๊ณผ Service ๋ค์ด ์๋ก Domain Name ์ผ๋ก ํต์ ํ๊ธฐ ์ํด DNS ๋ฅผ ํ์ฉํ๋๋ฐ, K8s ์์ CoreDNS ์๋ฃจ์ ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก Deployment ํํ๋ก ๋ฐฐํฌ๋๋ฉฐ Service ์ญ์ ์ ๊ณตํด Pod ๊ณผ Service ๋ค์ด kube-dns Service ๋ฅผ ํฅํด nslookup ์ ์ํํ ์ ์๋ค.
kubectl get configmap -n kube-system
kubectl describe cm -n kube-system
CoreDNS ์ ์ค์ ์ ConfigMap ์ผ๋ก ๊ตฌ์ฑ ๊ฐ๋ฅํ๋ค.
cat /var/lib/kubelet/config.yaml | grep -A2 clusterDNS
clusterDNS:
- 10.96.0.10
clusterDomain: cluster.local
CoreDNS ๋ kubelet ์ผ๋ก ๋ถํฐ ๋ฐฐํฌ๋๊ธฐ์ kubelet ์ ์ค์ ํ์ผ์์ CoreDNS ์ IP ๋ฅผ ํ์ธํ ์ ์๋ค.
kubectl run -it --rm --restart=Never test-pod --image=busybox -- cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
pod "test-pod" deleted
Pod ๋ด๋ถ์ ์๋ resolv.conf
ํ์ผ์์ CoreDNS IP ๊ฐ ์ ์ฉ๋์ด ์๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
Ingress
Ingress ๋ ๋ค์ํ Service ๋ก์ ํธ๋ํฝ์ ๊ตฌ๋ถํ๊ณ ๋ถ์ฐํ๋ ์ผ์ข ์ Load Balancer ์ญํ ์ ํ๋ค. Ingress ๋ Ingress Controller ์ Ingress Resoucres ๋ก ๊ตฌ์ฑ๋๋ค.
Ingress Controller
apiVersion: apps/v1
kind: Deployment
metadata:
name: ingress-controller
spec:
replicas: 1
selector:
matchLabels:
name: nginx-ingress
template:
metadata:
labels:
name: nginx-ingress
spec:
serviceAccountName: ingress-serviceaccount
containers:
- name: nginx-ingress-controller
image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.21.0
args:
- /nginx-ingress-controller
- --configmap=$(POD_NAMESPACE)/nginx-configuration
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- name: http
containerPort: 80
- name: https
containerPort: 443
apiVersion: v1
kind: Service
metadata:
name: ingress
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
selector:
name: nginx-ingress
GCP Load Balancer, Nginx, Istio ๋ฑ์ด ์ด์ ํด๋นํ๋ฉฐ Deployment, Service, ConfigMap, Auth ๋ฑ ๋ค์ํ K8s Object ๋ก ๊ตฌ์ฑ๋๋ค.
Ingress Resource
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-wear-watch
spec:
rules:
- host: wear.my-online-store.com
http:
paths:
- backend:
serviceName: wear-service
servicePort: 80
- host: watch.my-online-store.com
http:
paths:
- backend:
serviceName: watch-service
servicePort: 80
ํธ๋ํฝ ๋ผ์ฐํ ๋ฃฐ์ ์ค์ ํ๋ ๊ณณ์ผ๋ก Ingress Object ๊ฐ ์ฌ๊ธฐ์ ์ฌ์ฉ๋๋ค.
Gateway API
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: example-class
spec:
controllerName: example.com/gateway-controller
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: example-gateway
spec:
gatewayClassName: example-class
listeners:
- name: http
protocol: HTTP
port: 80
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: example-httproute
spec:
parentRefs:
- name: example-gateway
hostnames:
- "www.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /login
backendRefs:
- name: example-svc
port: 8080
Ingress ์ ๊ฒฝ์ฐ Ingress Controller ๊ฐ Nginx ์ธ์ง, Traefik ์ธ์ง์ ๋ฐ๋ผ annotation ์์ ํด์ฃผ๋ ์ค์ ์ด ๋ฌ๋ผ์ง ์ ์๋ค. K8s ์์ ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด Gateway API ๋ผ๋ ํ๋ก์ ํธ๋ฅผ ์์ํ๊ณ , ์ ๊ณต๋๋ GatewayClass, Gateway, HTTPRoute ๋ฑ ์๋ก์ด Object ๋ฅผ ํตํด Controller ์ ์ข ์๋์ง ์๋ ์ค์ ์ ํด์ค ์ ์๋ค.