Kubernetes

쿠버네티스는 컨테이너화된 워크로드와 서비스를 관리하기 위한 이식성이 있고, 확장가능한 오픈소스 플랫폼이다. 쿠버네티스는 선언적 구성과 자동화를 모두 용이하게 해준다. 쿠버네티스는 크고, 빠르게 성장하는 생태계를 가지고 있다. 쿠버네티스 서비스, 기술 지원 및 도구는 어디서나 쉽게 이용할 수 있다.

쿠버네티스란 명칭은 키잡이(helmsman)나 파일럿을 뜻하는 그리스어에서 유래했다. K8s라는 표기는 "K"와 "s"와 그 사이에 있는 8글자를 나타내는 약식 표기이다. 구글이 2014년에 쿠버네티스 프로젝트를 오픈소스화했다. 쿠버네티스는 프로덕션 워크로드를 대규모로 운영하는 15년 이상의 구글 경험과 커뮤니티의 최고의 아이디어와 적용 사례가 결합되어 있다.

Docker

0. Docker 
1. sudo apt-get remove docker docker-engine docker.io containerd runc
2. sudo apt-get update
3. sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
4. Add Docker’s official GPG key
   : curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    --> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker.gpg 이거로 바뀐듯 
5. sudo apt-key fingerprint 0EBFCD88
        smend@smend-Slave:~$ sudo apt-key fingerprint 0EBFCD88
        pub   rsa4096 2017-02-22 [SCEA]
                  9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
        uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
        sub   rsa4096 2017-02-22 [S]
6. 
        sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
  * --> Raspberry Pi 4 : deb [arch=armhf] https://download.docker.com/linux/raspbian buster stable
7. sudo apt-get update
8. sudo apt-get install docker-ce docker-ce-cli containerd.io
9. sudo usermod -aG docker $USER 그리고 재로그인 

Master / Slave 공통

Master / Slave 공통

Master ROOT user only

Master ROOT user only

20231010 결과 

kubeadm join 192.168.0.130:6443 --token zf4ub4.aa659burc1jlp42u \
        --discovery-token-ca-cert-hash sha256:dfb5baf24d4e8eec7f9e54a8ce5a376688d8a9d5222496fa0eb0e1c845a22eb4



Slave Node

Slave Node

Dashboard

Dashboard

Ingress

Ingress 

* INGRESS를 사용한 쿠버네티스 네트워크 설치 및 연결

Private Docker Registry

Private Docker Registry

  1. Docker registry Images 가져오기
     docker pull registry:latest
  2. docker images
  3. hyunsu@kubemaster:/etc/docker/registry$ sudo mv ./config.yml ./config.yml.20201022
  4. config

    version: 0.1
    log:
      fields:
        service: registry
    storage:
      cache:
        blobdescriptor: redis
      filesystem:
        rootdirectory: /data/registry
    redis:
      addr: redis:6379
    http:
      addr: :5000
      headers:
        X-Content-Type-Options: [nosniff]
    health:
      storagedriver:
        enabled: true
        interval: 10s
        threshold: 3
  5. docker run -d -p 9002:5000 -e REGISTRY_STORAGE_DELETE_ENABLED=true  --restart=always --name JoangPrivateDocker -v /home/hyunsu/config.yml:/home/hyunsu/config.yml registry:2
    : -e REGISTRY_STORAGE_DELETE_ENABLED=true 옵션은 이미지를 삭제를 할 수 있다는 의미로 아래 DELETE 명령이 동작한다. 
    안하면 {"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]} 오류가 발생 

  6. docker ps -a
  7. docker ps -l (최근)
  8. netstat -an | grep 9002 (확인)


Private Docker 사용

  1. docker build -t tomcat-meta:0.1 .
  2. docker tag tomcat-meta:0.1 web.joang.com:9002/tomcat-meta:0.1
  3. docker tag를 이용하여 docker registry에 push
    cat /etc/docker/daemon.json
    {
     "insecure-registries" : ["192.168.0.130:9002"]
    }
    systemctl restart docker
  4. docker push web.joang.com:9002/tomcat-meta:0.1
  5. 확인 http://192.168.0.100:9002/v2/_catalog

  6. http://192.168.0.100:9002/v2/meta-meta/tags/list

주의 : 기본적으로 https를 사용해야 하는데 https를 쓰는 걍우 push 에서 오류가 난다. 
The push refers to repository [192.168.0.100:9002/tomcat-meta-batch]
Get https://192.168.0.100:9002/v2/: http: server gave HTTP response to HTTPS client
The push refers to repository [192.168.0.100:9002/tomcat-meta-batch]
Get https://192.168.0.100:9002/v2/: http: server gave HTTP response to HTTPS client
---> 따라서 보안을 http접근을 하용 해야 한다. 
sudo vi /etc/docker/daemon.json  를 아래와 같이 수정 

{
 "insecure-registries" : ["web.joang.com:9002"]
}

IP로 하니까 오류 발생 !!!!!

127.0.1.1       web.joang.com 추가 !

127.0.0.1       localhost
127.0.1.1       kubemaster
127.0.1.1       web.joang.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

20231003 오류 발생 
[Docker] private registry http: server gave HTTP response to HTTPS client 해결 방법


1. 리포지토리 조회

 - Usage : curl -X GET <Repository URL/v2/_catalog>

http://web.joang.com:9002/v2/_catalog

2. 삭제할 리포지토리의 Tag 조회

 - Usage : curl -X GET <Repository URL/v2/<repository 이름>/tag/list

http://web.joang.com:9002/v2/tomcat-meta/tags/list

3. content digest(hash) 조회(registry 컨테이너가 작동중인 노드에서 실행)

 - Usage : curl -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET <Repository URL>/v2/<Repository 이름>/manifests/<Tag> 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}' 

예) curl -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://192.168.0.100:9002/v2/joang-mediawiki/manifests/1 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}'

--> 결과 sha256:e9c342dfa34bf2c3cf58503db8bc9a1298e233fadfbd6551ecea83aca80d701a

예) curl -XGET -v -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://registry.hoya.com/v2/ubuntu/manifests/17.04

4. manifest 삭제

 - Usage 1 : curl -X DELETE <Repository URL>/v2/<Repository 이름>/manifests/<content digest>

예) curl -X DELETE https://registry.hoya.com/v2/ubuntu/manifests/sha256:213e05583a7cb8756a3f998e6dd65204ddb6b4c128e2175dcdf174cdf1877459

5. GC(Garbage Collection) 실행 : Garbage 이미지 삭제

 - Usage : docker exec -it registry  bin/registry garbage-collect  /etc/docker/registry/config.yml 

docker exec -it JoangPrivateDocker registry garbage-collect /etc/docker/registry/config.yml

6. 레지스트리 서버 재시작

docker stop registry

docker start registry

예) Registry 파일시스템내에서 파일 삭제

shell> curl -X GET https://registry.hoya.com/v2/_catalog 
{"repositories":["debian","ubuntu"]}

shell> curl -X GET https://registry.hoya.com/v2/ubuntu/tags/list 
{"name":"ubuntu","tags":["17.04","18.04"]}

shell> curl -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET https://registry.hoya.com/v2/ubuntu/manifests/17.04 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}'
sha256:213e05583a7cb8756a3f998e6dd65204ddb6b4c128e2175dcdf174cdf1877459

shell> docker exec -it registry sh      => registry container에 shell로 접속
/ # cd /var/lib/registry/docker/registry/v2
/var/lib/registry/docker/registry/v2 # rm -rf ./repositories/ubuntu/_manifests/tags/17.04  
/var/lib/registry/docker/registry/v2 # rm -rf ./repositories/ubuntu/_manifests/revisions/sha256/<content-digest>

shell> docker exec -it registry  bin/registry garbage-collect  /etc/docker/registry/config.yml 

shell> docker stop registry 
shell> docker start registry

리포지토리 삭제

예시) ubuntu 리파지토리 삭제

shell> curl -X GET https://registry.hoya.com/v2/_catalog
{"repositories":["debian","ubuntu"]}

shell> docker exec -it registry sh      => registry container에 shell로 접속
/ # cd /var/lib/registry/docker/registry/v2
/var/lib/registry/docker/registry/v2 # rm -rf ./repositories/ubuntu/   => 레파지토리 삭제
/var/lib/registry/docker/registry/v2 # exit

shell> docker exec -it registry  bin/registry garbage-collect  /etc/docker/registry/config.yml 

shell> docker stop registry
shell> docker start registry

TroubleShooting

증상 ) curl 명령어를 이용하여  삭제시 아래(붉은 글씨) 와 오류가 발생할 경우

> DELETE /v2/ubuntu/manifests/sha256:e5dd9dbb37df5b731a6688fa49f4003359f6f126958...............                                           
> User-Agent: curl/7.29.0
> Host: registry.hoya.com
> Accept: application/vnd.docker.distribution.manifest.v2+json
>
HTTP/1.1 405 Method Not Allowed
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< X-Content-Type-Options: nosniff
< Date: Thu, 02 Apr 2020 03:24:55 GMT
< Content-Length: 78
<
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}
* Connection #0 to host registry.hoya.com left intact

원인) 

registry 시작시 환경변수   -e REGISTRY_STORAGE_DELETE_ENABLED=true 를 지정하지 않았을 경우 DELETE 메소드가 허용되지 않는다.

조치)

Registry 시작시  "-e REGISTRY_STORAGE_DELETE_ENABLED=true" 환경변수를 추가해서 서비스를 시작한다. 

- TroubleShooting

증상) curl 명령어 실행시 아래와 같은 오류 발생

 - 데비안, 우분투

shell> curl -X GET https://registry.hoya.com/v2/_catalog 
curl: (60) SSL certificate problem: self signed certificate in certificate chain 
More details here: https://curl.haxx.se/docs/sslcerts.html 

curl failed to verify the legitimacy of the server and therefore could not 
establish a secure connection to it. To learn more about this situation and 
how to fix it, please visit the web page mentioned above. 
shell>

 - CentOS

shell> curl -X GET https://registry.hoya.com/v2/_catalog 
curl: (60) Peer's certificate issuer has been marked as not trusted by the user. 
More details here: http://curl.haxx.se/docs/sslcerts.html 

curl performs SSL certificate verification by default, using a "bundle" 
 of Certificate Authority (CA) public keys (CA certs). If the default 
 bundle file isn't adequate, you can specify an alternate file 
 using the --cacert option. 
If this HTTPS server uses a certificate signed by a CA represented in 
 the bundle, the certificate verification probably failed due to a 
 problem with the certificate (it might be expired, or the name might 
 not match the domain name in the URL). 
If you'd like to turn off curl's verification of the certificate, use 
 the -k (or --insecure) option. 
shell>

원인)

registry 컨터이너가 사설 인증서를 사용해서 서비스를 할경우 curl 에서 인증서 오류 발생

조치)

 1. 데비안, 우분투

/usr/local/share/ca-certificates 디렉토리에 사설 rootca 인증서를 등록후 update-ca-certificates 명령어 실행

shell> cp rootca.crt /usr/local/share/ca-certificates
shell>  update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
shell>

 2. CentOS 

/etc/pki/ca-trust/source/anchors/ 디렉토리에 사설 rootca 인증서를 등록후 update-ca-trust명령어 실행

shell> cp rootca.crt /etc/pki/ca-trust/source/anchors/
shell> update-ca-trust

 3. curl 명령어에 -k 또는 --inscure 옵션 사용

shell> curl -k https://www.domain.com 
OR shell> curl --insecure https://www.domain.com

Private image delete

  1. curl -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://192.168.56.3:9002/v2/tomcat-synapse/manifests/0.1 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}'

  2. curl -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X DELETE http://192.168.56.3:9002/v2/tomcat-synapse/manifests/sha256:65336b7ee5a56dc2a7294c02fbb515542e5212a7ea193943160d9ecbb4ca0f62

  3. GC(Garbage Collection)
    docker exec -it JoangPrivateDocker registry garbage-collect /etc/docker/registry/config.yml
  4. Image 정리
    docker image prune -f

기타 Kubernetes command

기타 Kubernetes command

좀비pod가 있을 때 강제 삭제

Namespace 삭제

reboot 시에 private registry 비정상 동작

Ingress path / only work

Pod에 들어가기 

kubectl exec -it -n meta-apps meta-meta-59b56f6694-smtmq -- bash

 

Pod 재시작 

kubectl rollout restart ds -n kube-system weave-net

 

Istio Kiali

Kiali (Kubernetes add on for istio) 소개 

image.png

image.png


출처 : 이종하님 

Pinpoint 소개 

Pinpoint는 분산 서비스 및 시스템의 성능 분석/진단/추적 플랫폼 서비스로서 “N” 계층의 SOA(Service Oriented Architecture) 및 Micro-Service로 구성된 아키텍처 서비스의 추적 및 분석 기능을 제공하고, 분산 애플리케이션의 트랜잭션 분석, Topology Detection, Bytecode Instrumentation을 활용한 진단 기능을 제공

image.png

https://guide-fin.ncloud-docs.com/docs/pinpoint-pinpoint-1-1 

Istio 설치 시 선택 profile 

Kubernetes 버전에 따른 Istio 버전   

Version Currently Supported Release Date End of Life Supported Kubernetes Versions Tested, but not supported
master No, development only     1.29, 1.30, 1.31, 1.32 1.23, 1.24, 1.25, 1.26, 1.27, 1.28
1.24 Yes November 7, 2024 ~Aug 2025 (Expected) 1.28, 1.29, 1.30, 1.31 1.23, 1.24, 1.25, 1.26, 1.27
1.23 Yes Aug 14, 2024 ~May 2025 (Expected) 1.27, 1.28, 1.29, 1.30 1.23, 1.24, 1.25, 1.26
1.22 Yes May 13, 2024 ~Jan 2025 (Expected) 1.27, 1.28, 1.29, 1.30 1.23, 1.24, 1.25, 1.26
1.21 Yes Mar 13, 2024 Sept 27, 2024 1.26, 1.27, 1.28, 1.29 1.23, 1.24, 1.25
1.20 No Nov 14, 2023 Jun 25, 2024 1.25, 1.26, 1.27, 1.28, 1.29 1.23, 1.24
1.19 No Sept 5, 2023 Apr 24, 2024 1.25, 1.26, 1.27, 1.28 1.21, 1.22, 1.23, 1.24
1.18 No Jun 3, 2023 Jan 4, 2024 1.24, 1.25, 1.26, 1.27 1.20, 1.21, 1.22, 1.23
1.17 No Feb 14, 2023 Oct 27, 2023 1.23, 1.24, 1.25, 1.26 1.16, 1.17, 1.18, 1.19, 1.20, 1.21, 1.22
1.16 No Nov 15, 2022 Jul 25, 2023 1.22, 1.23, 1.24, 1.25 1.16, 1.17, 1.18, 1.19, 1.20, 1.21
1.15 No Aug 31, 2022 Apr 4, 2023 1.22, 1.23, 1.24, 1.25 1.16, 1.17, 1.18, 1.19, 1.20, 1.21
1.14 No May 24, 2022 Dec 27, 2022 1.21, 1.22, 1.23, 1.24 1.16, 1.17, 1.18, 1.19, 1.20
1.13 No Feb 11, 2022 Oct 12, 2022 1.20, 1.21, 1.22, 1.23 1.16, 1.17, 1.18, 1.19

The components marked as ✔ are installed within each profile:

  default demo minimal remote empty preview ambient
Core components              
      istio-egressgateway            
      istio-ingressgateway        
      istiod    
      CNI            
      Ztunnel            

To further customize Istio, a number of addon components can also be installed. Refer to integrations for more details.

Istio 설치 

curl -L https://istio.io/downloadIstio | sh -    <-- 받아서 확인하고 실행 필요 
cd istio-1.9.1
export PATH=$PWD/bin:$PATH

istioctl profile list
istioctl install --set profile=demo -y

[hyunsu@2-RockyKubeMaster ~]$ istioctl install --set profile=default -y
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
✔ Installation complete                                                                                                       Making this installation the default for injection and validation.

Thank you for installing Istio 1.17.  Please take a few minutes to tell us about your install/upgrade experience!  https://forms.gle/hMHGiwZHPU7UQRWe9
[hyunsu@2-RockyKubeMaster ~]$


kubectl label namespace showcase1-apps istio-injection=enabled

Kiali 설치 

Istio Kiali Min Kiali Max Notes
1.24 2.0.0    
1.23 1.87.0 2.0.0 Kiali v2 requires Kiali v1 non-default namespace management (i.e. accessible_namespaces) to migrate to Discovery Selectors.
1.22 1.82.0 1.86.2 Kiali v1.86 is the recommended minimum for Istio Ambient users. v1.22 is required starting with Kiali v1.86.1.
1.21 1.79.0 1.81.0 Istio 1.21 is out of support.
1.20 1.76.0 1.78.0 Istio 1.20 is out of support.
1.19 1.72.0 1.75.0 Istio 1.19 is out of support.
1.18 1.67.0 1.73.0 Istio 1.18 is out of support.
1.17 1.63.2 1.66.1 Istio 1.17 is out of support. Avoid 1.63.0,1.63.1 due to a regression.
1.16 1.59.1 1.63.2 Istio 1.16 is out of support. Avoid 1.62.0,1.63.0,1.63.1 due to a regression.
1.15 1.55.1 1.59.0 Istio 1.15 is out of support.
1.14 1.50.0 1.54 Istio 1.14 is out of support.
1.13 1.45.1 1.49 Istio 1.13 is out of support.
1.12 1.42.0 1.44 Istio 1.12 is out of support.
1.11 1.38.1 1.41 Istio 1.11 is out of support.
1.10 1.34.1 1.37 Istio 1.10 is out of support.
1.9 1.29.1 1.33 Istio 1.9 is out of support.
1.8 1.26.0 1.28 Istio 1.8 removes all support for mixer/telemetry V1, as does Kiali 1.26.0. Use earlier versions of Kiali for mixer support.
1.7 1.22.1 1.25 Istio 1.7 istioctl no longer installs Kiali. Use the Istio samples/addons for quick demo installs. Istio 1.7 is out of support.
1.6 1.18.1 1.21 Istio 1.6 introduces CRD and Config changes, Kiali 1.17 is recommended for Istio < 1.6.

인증서 교체

인증서 교체 

 수동 인증서 교체 

1. 인증서 일자 확인

$ kubeadm certs check-expiration

2. 혹시모를 사태에 대비하여 인증서 백업

$ cp -r /etc/kubernetes ~/backups

3. 인증서 갱신

$ kubeadm certs renew all

5. kube-apiserver, kube-controller-manager, kube-scheduler재시작

$ kill -s SIGHUP $(pidof kube-apiserver)
$ kill -s SIGHUP $(pidof kube-controller-manager)
$ kill -s SIGHUP $(pidof kube-scheduler)
$ systemctl restart kubelet
$ systemctl daemon-reload
$ systemctl restart docker
( docker 재시작 이후엔 중지된 컨테이너들을 실행해줘야한다.)

6. apiserver, controller-manager, scheduler 가 재실행되었는지 AGE 확인

$ kubectl get pods --all-namespaces -o wide

7. 인증서 복사

$ cp /etc/kubernetes/admin.conf /root/.kube/config

8. node 조회

$ kubectl get nodes
$ kubeadm certs check-expiration # 일자확인

정상적으로 출력되면 끝!

Containerd 명령어