티스토리 뷰

Containerd를 Kubernetes runtime으로 사용하는 근래의 환경에서 docker insecure 설정과 같은 설정을 해야할 상황이 있어 이를 기술해보았다.
아래 링크를 기반으로 /etc/containerd/certs.d/ 하위에 디렉토리 및 hosts.toml을 생성하여 설정을 진행한다.

테스트 환경

  • nexus 를 docker-compose로 동작 (5000 포트로 http 연결만 가능하도록)
  • nginx image를 nexus상에 push 하여 pull 가능한 이미지 구성

아래와 같이 http로 연결을 시도하면 "http: server gave HTTP response to HTTPS client" 와 같은 메세지를 보게 되고 ImagePullBackOff 상태가 된다.

root@node1:/etc/containerd/certs.d/10.224.0.100:5000# crictl pull 10.224.0.100:5000/nginx
E0202 08:49:40.625050   54008 remote_image.go:242] "PullImage from image service failed" err="rpc error: code = Unknown desc = failed to pull and unpack image \"10.224.0.62:5000/nginx:latest\": failed to resolve reference \"10.224.0.62:5000/nginx:latest\": failed to do request: Head \"https://10.224.0.62:5000/v2/nginx/manifests/latest\": http: server gave HTTP response to HTTPS client" image="10.224.0.62:5000/nginx"
FATA[0000] pulling image: rpc error: code = Unknown desc = failed to pull and unpack image "10.224.0.62:5000/nginx:latest": failed to resolve reference "10.224.0.62:5000/nginx:latest": failed to do request: Head "https://10.224.0.62:5000/v2/nginx/manifests/latest": http: server gave HTTP response to HTTPS client

위와 같은 이슈가 발생되는것은 일반적으로 containerd든 docker든 runtime이 동작되는 환경은 container image에 registry에 대한 연결을 https를 default로 가진다. 그렇기에 http로 연결하게 되면 위와 같은 이슈가 발생되게 된다.

이와 같은 경우는 각 노드에 다음 설정이 존재해야 한다.
(별도의 containerd 재시작이 필요하지는 않고 설정파일만 이름과 잘 매핑하여 존재하면 된다.)

## 여기서 10.224.0.100은 nexus 서버 주소 이며 5000 포트는 nexus에서 docker hosted 모드로 listen하는 port이다.
root@node1:/# mkdir -p /etc/containerd/certs.d/10.224.0.100:5000
root@node1:/# cat /etc/containerd/certs.d/10.224.0.100\:5000/hosts.toml
server = "http://10.224.0.100:5000"

[host."http://10.224.0.100:5000"]
  capabilities = ["pull", "resolve", "push"]
  skip_verify = true

이후 pod를 다음과 같이 배포하게 되면

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: 10.224.0.100:5000/nginx
        ports:
        - containerPort: 80

아래와 같이 정상적으로 image pull이 이루어진다.

Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  3m37s  default-scheduler  Successfully assigned default/nginx-deployment-5d8c4b74b6-scngl to node1
  Normal  Pulling    3m37s  kubelet            Pulling image "10.224.0.62:5000/nginx"
  Normal  Pulled     3m36s  kubelet            Successfully pulled image "10.224.0.62:5000/nginx" in 140.198312ms
  Normal  Created    3m36s  kubelet            Created container nginx
  Normal  Started    3m36s  kubelet            Started container nginx

다양한 설정

https://github.com/containerd/containerd/blob/main/docs/hosts.md

아래 코드상에서 확인해보면

hosts로 시작되는 설정정보를 가져오는것은 다음

  • skipVerify
  • Capabilities
  • CACert
  • Client
  • Header

인증정보는 아직 추가되지 않은것으로 보인다.

개인적으로 유추해보면 인증서를 통한 인증을 수행하도록 권장하는 느낌이다.
TODO에 있으니 언젠간 개발이되겠지만...

daemonset을 이용한 영속적인 설정

위 설정은 노드의 재부팅이 있는 경우 설정이 초기화 된다.
이를 고정적으로 사용할 수 있도록 하기 위해 아래와 같은 daemonset을 구성한다.

결론적으로 이야기하자면 daemonset을 이용해도 쉽게 구성하기가 어렵다.
이유는 container registry의 접근 주소를 directory로 구성해야 해서 이를 구현하기가 쉽지 않기 때문이다.
혹여나 dynamic 하게 directory를 구현할 방법을 찾게되면 이를 서술할 예정이다.
다만 이 방법을 추천하고 싶지는 않다.

참고사이트

'Cloud > Kubernetes' 카테고리의 다른 글

kubent(no trouble)  (0) 2023.03.14
Vertical Pods Autoscaler  (0) 2023.02.16
cert-manager with ingress-nginx  (0) 2023.02.13
fluent-bit with azure service  (0) 2023.01.02
Kaniko  (0) 2022.12.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함