kube 3

ingress
cloud-computing

인그레스(Ingress) 오브젝트의 기본 기능


사용하는 이유


예제

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-example
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: alicek106.example.com # [1]
      http:
        paths:
          - path: /echo-hostname # [2]
            pathType: Prefix
            backend:
              service:
                name: hostname-service # [3]
                port:
                  number: 80
$ kubectl apply -f ingress-example.yaml
$ kubectl get ing

인그레스 컨트롤러 (ingress controller)

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.0/deploy/static/provider/aws/deploy.yaml

# ingress-nginx 네임스페이스의 디플로이먼트와 파드를
# 확인해보면 nginx 웹서버가 생성됨
$ kubectl get pods,deployment -n ingress-nginx

# 외부에서 nginx 인그레스 컨트롤러에 접근하기 위한 서비스도 생성됨
$ kubectl get svc -n ingress-nginx


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


인그레스 컨트롤러의 동작 원리

  1. 공식 깃허브에서 제공되는 YAML 파일로 nginx 인그레스 컨트롤러를 생성한다.
  2. nginx 인그레스 컨트롤러를 외부로 노출하기 위한 서비스를 생성한다.
  3. 요청 처리 규칙을 정의하는 인그레스 오브젝트를 생성한다.
  4. nginx 인그레스 컨트롤러로 들어온 요청은 인그레스 규칙에 따라 적절한 서비스로 전달된다.


# ENDPOINTS 항목에 출력된 지점으로 요청이 전달된다.
$ kubectl get endpoints


Azure


Azure kubernetes tutorial

# 그전에 띄워놨던 것들 yaml파일 기반으로 다 제거
$ kubectl delete -f ./

# brew 최신화
$ brew update

# kubectl처럼 애져명령어 치기 위한 의존 설치
$ brew install azure-cli

# 튜토리얼 진행
$ git clone https://github.com/Azure-Samples/azure-voting-app-redis.git
$ cd azure-voting-app-redis
$ docker-compose up -d

# `todorepo`는 애져에 만든 컨테이너 레지스트리명
$ docker tag mcr.microsoft.com/azuredocs/azure-vote-front:v1 todorepo.azurecr.io/azure-vote-front:v1

$ az acr login --name todoRepo
$ docker push todorepo.azurecr.io/azure-vote-front:v1
$ az acr repository list --name todoRepo --output table

# kubectl을 만든 쿠버네티스 클러스터를 바라보도록 연결
$ az aks get-credentials --resource-group study --name todoCluster
$ kubectl apply -f azure-vote-all-in-one-redis.yaml
$ kubectl get service azure-vote-front --watch

# 이후 EXTERNAL IP로 접근하면 튜토리얼 화면이 뜬다.


애져 리소스그룹 삭제한 후의 로컬에서 컨텍스트 스위칭하기

$ kubectl config get-contexts
$ kubectl config unset clusters.todoCluster
$ kubectl config unset contexts.todoCluster
$ kubectl config unset users.clusterUser_study_todoCluster
$ kubectl config use-context docker-desktop
$ kubectl config view

# 이제 config를 보면 현재 컨텍스트가 docker-desktop이다.


쿠버네티스 yaml 파일들 있을 때 전체 삭제하기

~ kubectl delete -f ./

deployment.apps "hostname-deployment" deleted
service "hostname-service" deleted
ingress.networking.k8s.io "ingress-example" deleted
deployment.apps "todo-deployment" deleted
Error from server (NotFound): error when deleting "ingress-nginx-svc-nodeport.yaml": services "ingress-nginx-controller-nodeport" not found
Error from server (NotFound): error when deleting "todo-pod.yaml": pods "todo-pod" not found
Error from server (NotFound): error when deleting "todo-replicaset.yaml": replicasets.apps "todo-replicaset" not found
unable to decode ".angular-config.json": Object 'Kind' is missing in '{
  "version": 1,
  "cli": {
    "analytics": false
  }
}'