Legacy Engineering Note · 기존 기술 블로그에서 선별 이관한 기록입니다. 작성 당시 환경과 버전을 기준으로 합니다.
1. Jenkins Build용 VM 환경 구성
1) VM 환경
- OS : Ubuntu 20.04 LTS
- JDK 17
- Gradle
- Maven
- Docker
- kubectl
2) JDK, Gradle, Maven 설치
shellsudo apt update sudo apt-get install openjdk-17-jdk -y sudo apt install gradle -y sudo apt install maven -y
3) Docker 환경 구성
1. Docker 설치
shellsudo wget -qO- http://get.docker.com/ | sh
2. Docker 활성화
shellsudo systemctl enable docker sudo systemctl start docker sudo systemctl enable containerd sudo systemctl start containerd
3. Docker 컨테이너 실행 테스트
shelljenkins-agent@Jenkins-Agent:~$ sudo docker run --rm hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c1ec31eb5944: Pull complete Digest: sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
4. 생성된 Docker image 삭제
shelljenkins-agent@Jenkins-Agent:~$ sudo docker rmi $(sudo docker images -q) Untagged: hello-world:latest Untagged: hello-world@sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6 Deleted: sha256:d2c94e258dcb3c5ac2798d32e1249e42ef01cba4841c2234249495f87264ac5a Deleted: sha256:ac28800ec8bb38d5c35b49d45a6ac4777544941199075dff8c4eb63e093aa81e jenkins-agent@Jenkins-Agent:~$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE
5. Docker의 cgroup driver를 cgroupfs에서 systemd로 변경
shell#sudo mkdir /etc/docker cat <<EOF | sudo tee /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2" } EOF # 재시작 sudo systemctl enable docker sudo systemctl daemon-reload sudo systemctl restart docker # 변경된 cgroup driver 확인 sudo docker info | grep -i cgroup
6. Swap 메모리를 비활성화 [root 권한 필요]
shell# swap disable swapoff -a echo 0 > /proc/sys/vm/swappiness sed -e '/swap/ s/^#*/#/' -i /etc/fstab # 실행 참고 jenkins-agent@Jenkins-Agent:~$ sudo su - root@Jenkins-Agent:~# swapoff -a root@Jenkins-Agent:~# echo 0 > /proc/sys/vm/swappiness root@Jenkins-Agent:~# sed -e '/swap/ s/^#*/#/' -i /etc/fstab
4) Kubectl 설치
1. apt-key를 통해 GPG 키 추가
shellcurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
2. Kubernetes 패키지 저장소를 APT 소스 목록에 추가
shellcat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF
3. APT 패키지 목록 업데이트
shellsudo apt-get update
4. kubernetes 설치
shellsudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl sudo apt-get update sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.100.6
5. kubectl 설치 확인
shelljenkins-agent@Jenkins-Agent:~$ kubectl get pods E0730 04:50:54.162684 25615 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0730 04:50:54.163036 25615 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0730 04:50:54.164441 25615 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0730 04:50:54.164754 25615 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused E0730 04:50:54.166074 25615 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused The connection to the server localhost:8080 was refused - did you specify the right host or port?
6. Kubeconfig 파일 설정
shellsudo mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config