Rancher-Desktop 으로 Kubernetes 사용하기 With WSL (2)

2023. 5. 1. 00:00DevOps/Kubernetes

반응형

이전 내용

https://yogingang.tistory.com/426

 

Windows 에서 WSL2 에 Docker Desktop 없이 docker 설치

이전 version WSL 삭제 이전에 깔려 있던 WSL 이 있다면 과감히 삭제 하자. 윈도우스 10 에서 프로그램 제거 또는 변경 (설정 --> 앱 및 기능 에서 삭제해도 된다.) linux 관련 삭제 ubuntu 관련 삭제 check 해

yogingang.tistory.com

https://yogingang.tistory.com/429

 

Rancher-Desktop 으로 Kubernetes 사용하기 With WSL

Rancher-Desktop 설치 먼저 Rancher Desktop 를 download 하자 download (1.8.1 version) https://rancherdesktop.io/ 재부팅 후 다시 실행 위와 같이 뭔가 좀더 download 하고 설치한다. 설치가 다 될때까지 기다리자 톱니바퀴

yogingang.tistory.com

 

일단 간단 docker 관련 image 를 생성 하고 실행해 보자

mkdir hello-world
cd hello-world

Dockerfile 을 만들자 확장자는 없다.

그리고 다음을 입력하고 저장하자

FROM alpine  
CMD ["echo", "Hello World!!"]

이제 docker 명령을 통해 build 하고 run 해보자

docker build --tag helloworld:v1.0 .
docker images | findstr /s helloworld
docker run --rm helloworld:v1.0

위의 명령들을 차례대로 실행하면 console 창에 다음과 같은 내용이 나온다.

 

Hello World!!

 

이제 docker image 를 삭제 하자

# Remove the image
docker rmi helloworld:v1.0

이제 Kubernetes 에서 image 를 build 하고 deploy 해보겠다. 

rancher-desktop 에서 dockerd 선택 되어 있는지 다시 한번 확인하자.

아래 명령을 차례대로 실행해보자

mkdir nginx
cd nginx
echo "<h1>Hello World from NGINX!!</h1>" > index.html

다시 해당 폴더에 Dockerfile 을 만들자.

** PowerShell 에서 몇몇 linux 명령을 직접 사용할 수 있다. 그중에서 vi 와 nano 도 사용가능 하다.***

:: PowerShell 에서 사용가능
bash -c "nano Dockerfile"

다음을 입력 하자

FROM nginx:alpine
COPY . /usr/share/nginx/html

이제 docker 로 image 를 build 하자

docker build --tag nginx-helloworld:latest .

이미지가 생성되었는지 확인하자

docker images | findstr /s nginx-helloworld

이제 kubectl 을 통해 kubernetes 에 deploy 하자!!

kubectl run hello-world --image=nginx-helloworld:latest --image-pull-policy=Never --port=80

port-forward 를 통해서 pod 내에 container 의 port 를 fowarding 하자

pod 내의 80 번 port 를  실제 os 의 8080 번으로 fowarding 할 것이다. 

만약 오류가 나면 이미 사용하고 있는 port 일수 있으니 8080 번 주소를 바꾸어 보자.

kubectl port-forward pods/hello-world 8080:80

이제 browser 에서 실행해보자

아래와 같다면 정상 실행된 것이다. 

실행되고 있는 pod 를 중지하고 (ctrl + c)

kubernetes 에서 pod 를 삭제 하고 docker 를 통해 image 도 삭제 하자

kubectl delete pod hello-world 
# Remove the image
docker rmi nginx-helloworld:latest

여기 까지가 아주 간단한 docker image 생성 및 kubernetes 에 pod 를 생성하여 docker image 를 배포하고 실행한 내용이다.

 

 

 

관련영상

 

 

 

반응형