kubernetes
traefik-ingress-controller
misankim
2023. 3. 7. 00:00
traefik-ingress-controller
# traefik-ingress-controller 배포
cat << EOF > traefik-ingress-controller.yaml
apiVersion: v1
kind: Namespace
metadata:
name: traefik
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: traefik-ingress-controller
rules:
- apiGroups:
- ""
resources:
- services
- endpoints
- secrets
verbs:
- get
- list
- watch
- apiGroups:
- extensions
- networking.k8s.io
resources:
- ingresses
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- ingresses/status
verbs:
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: traefik-ingress-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: traefik-ingress-controller
subjects:
- kind: ServiceAccount
name: traefik-ingress-controller
namespace: traefik
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: traefik-ingress-controller
namespace: traefik
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: traefik
namespace: traefik
labels:
app: traefik
spec:
replicas: 1
selector:
matchLabels:
app: traefik
template:
metadata:
labels:
app: traefik
spec:
serviceAccountName: traefik-ingress-controller
containers:
- name: traefik
image: traefik:v2.5
args:
- --entrypoints.web.address=:80
- --api.insecure=true
- --providers.kubernetesingress
ports:
- name: web
containerPort: 80
- name: dashboard
containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: traefik
namespace: traefik
spec:
type: NodePort
selector:
app: traefik
ports:
- protocol: TCP
port: 80
name: web
targetPort: 80
- protocol: TCP
port: 8080
name: dashboard
targetPort: 8080
EOF
kubectl apply -f traefik-ingress-controller.yaml
kubectl get all -n traefik
# whoami 테스트 배포 생성
cat << EOF > whoami.yaml
apiVersion: v1
kind: Namespace
metadata:
name: whoami
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-whoami
namespace: whoami
labels:
app: traefiklabs
name: whoami
spec:
replicas: 2
selector:
matchLabels:
app: traefiklabs
task: whoami
template:
metadata:
labels:
app: traefiklabs
task: whoami
spec:
containers:
- name: whoami
image: traefik/whoami
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: service-whoami
namespace: whoami
spec:
ports:
- name: http
port: 80
selector:
app: traefiklabs
task: whoami
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-whoami
namespace: whoami
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host:
http:
paths:
- path: /bar
pathType: ImplementationSpecific
backend:
service:
name: service-whoami
port:
number: 80
- path: /foo
pathType: ImplementationSpecific
backend:
service:
name: service-whoami
port:
number: 80
EOF
kubectl apply -f whoami.yaml
kubectl get all -n whoami
# bootcamp 테스트 배포 생성
cat << EOF > bootcamp.yaml
apiVersion: v1
kind: Namespace
metadata:
name: bootcamp
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: bootcamp
name: deployment-bootcamp
spec:
selector:
matchLabels:
app.kubernetes.io/name: bootcamp
replicas: 3
template:
metadata:
labels:
app.kubernetes.io/name: bootcamp
spec:
containers:
- image: gcr.io/google-samples/kubernetes-bootcamp:v1
imagePullPolicy: Always
name: bootcamp
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
namespace: bootcamp
name: service-bootcamp
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
type: NodePort
selector:
app.kubernetes.io/name: bootcamp
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-bootcamp
namespace: bootcamp
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host:
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: service-bootcamp
port:
number: 80
EOF
kubectl apply -f bootcamp.yaml
kubectl get all -n bootcamp