DevOps/Kubernetes

[Kubernetes] 컨테이너 생성

잔망루피 2024. 4. 18. 23:25

컨테이너 생성

1. 폴더 생성 및 이동

mkdir test-image
cd test-image

 

 

2. 간단한 sh 파일 작성

cat > start.sh <<EOF
#!/bin/sh
echo "Hello, world! The time is $(date)."
EOF

 

 

3. Dockerfile 생성

cat > Dockerfile <<EOF
FROM alpine
COPY start.sh /
CMD ["/start.sh"]
EOF

 

 

4. 실행권한

chmod +x start.sh

 

 

5. 이미지 생성

gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/test-image .

 

이미지를 빌드했는데 docker images로 조회했을 때 안 뜨는 이유는 CloudBuild가 Docker build를 했기 때문이다.

Artifact Registry에 gcr.io에 들어가면,

생성된 test-image 도커 이미지를 볼 수 있다.

 

 

6. Deployment 생성

export my_zone=us-central1-c
export my_cluster=cluster-1

생성된 클러스터의 명, 지역을 환경변수로 등록

 

PROJECT_ID=$(gcloud config get-value project)
gcloud container clusters get-credentials $my_cluster --zone $my_zone --project $PROJECT_ID
kubectl create deployment --image gcr.io/$PROJECT_ID/test-image test-image

 

반응형

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

[Kubernetes] CI/CD  (1) 2024.06.11
[Kubernetes] helm  (0) 2024.06.09
[Kubernetes] 배포  (0) 2024.06.09
[Kubernetes] Workload 생성  (0) 2024.04.15
[Kubernetes] Standard 클러스터 생성  (0) 2024.04.12