Windows 환경에서 Gemini CLI와 MCP 서버를 이용해 Linux 가상 머신에 구축된 Kubernetes 클러스터를 자연어로 제어하기 위해 kubectl 설정부터 MCP 서버 연동까지의 과정을 기록한다.
MCP 서버는 https://github.com/Flux159/mcp-server-kubernetes 를 사용했다.
구성도

1. Windows에 kubectl 설정하기
Windows에서 Linux VM의 클러스터에 접근하기 위해 kubectl을 설정해야 한다. 공식 문서에 따라 직접 바이너리를 설치할 수도 있지만, 예전에 설치했었던 Docker Desktop에 내장된 kubectl을 활용했다.
1) Docker Desktop의 kubectl 활용
Docker Desktop은 설치 시 자체 kubectl을 시스템 PATH에 자동으로 추가해 준다. Get-Command로 확인해보면 경로를 알 수 있다.
PowerShell
PS C:\Users\HDV> Get-Command kubectl
CommandType Name Version Source
----------- ---- ------- ------
Application kubectl.exe 0.0.0.0 C:\Program Files\Docker\Docker\resources\bin\kubectl.exe
kubectl 클라이언트 버전은 v1.32.2로, 서버 버전(v1.32.3)과 거의 일치하여 호환성 문제는 없다.
PowerShell
PS C:\Users\HDV> kubectl version --client
Client Version: v1.32.2
Kustomize Version: v5.5.0
2) 원격 클러스터 정보 연동 (.kube/config)
kubectl이 클러스터 정보를 인식하려면 설정 파일인 config가 필요하다.
config파일 생성: Docker Desktop 설정에서 Kubernetes를Enable하면C:\Users\<사용자이름>\.kube\config파일이 자동으로 생성된다. 파일만 생성하고 다시Disable해도 파일은 남아있다.- 설정 복사: Linux VM에 있던
~/.kube/config파일의 내용을 복사하여, Windows의C:\Users\HDV\.kube\config파일에 그대로 붙여넣는다.
이제 Windows PowerShell에서 kubectl 명령으로 Linux VM의 클러스터 정보를 완벽하게 조회할 수 있다.
PowerShell
PS C:\Users\HDV> kubectl cluster-info
Kubernetes control plane is running at https://192.168.80.241:6443
CoreDNS is running at https://192.168.80.241:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
PS C:\Users\HDV> kubectl get node
NAME STATUS ROLES AGE VERSION
ygbaek1.cluster.com Ready control-plane 130d v1.32.3
ygbaek2.cluster.com Ready <none> 130d v1.32.3
ygbaek3.cluster.com Ready <none> 130d v1.32.3
ygbaek4.cluster.com Ready <none> 130d v1.32.3
2. Kubernetes MCP 서버 설치
이제 Gemini CLI가 자연어를 kubectl 명령으로 변환할 수 있도록 도와줄 MCP(Model-Context-Protocol) 서버를 설치한다. 이번에는 Flux159/mcp-server-kubernetes 프로젝트를 사용했다.
npm을 통해 간단하게 글로벌로 설치할 수 있다.
PowerShell
npm install -g mcp-server-kubernetes
3. Gemini CLI 설정 연동
마지막으로, Gemini CLI가 방금 설치한 MCP 서버를 사용하도록 설정 파일을 수정한다.
- 설정 파일 경로:
C:\Users\HDV\.gemini\setting.json
아래와 같이 mcpServers 항목에 kubernetes 서버를 추가한다.
JSON
{
"theme": "Default",
"selectedAuthType": "oauth-personal",
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": [
"mcp-kubernetes-server"
],
"env": {
"KUBECONFIG": "C:/Users/HDV/.kube/config"
}
}
}
}
command:npx를 사용해 글로벌 설치된 패키지를 실행한다.args: 실행할 MCP 서버 이름이다.env: MCP 서버가 실행될 때 필요한 환경 변수이다.KUBECONFIG경로를 명시하여 클러스터 정보를 정확히 찾도록 한다.
4. 확인
터미널에서 Gemini CLI를 실행하고 "모든 노드 목록을 보여줘" 또는 "default 네임스페이스에 있는 파드 알려줘" 와 같은 자연어 명령을 내리면, MCP 서버를 통해 kubectl이 실행되어 Linux VM에 있는 Kubernetes 클러스터의 정보를 가져오는 것을 확인할 수 있다.
PS C:\Users\HDV> gemini
███ █████████ ██████████ ██████ ██████ █████ ██████ █████ █████
░░░███ ███░░░░░███░░███░░░░░█░░██████ ██████ ░░███ ░░██████ ░░███ ░░███
░░░███ ███ ░░░ ░███ █ ░ ░███░█████░███ ░███ ░███░███ ░███ ░███
░░░███ ░███ ░██████ ░███░░███ ░███ ░███ ░███░░███░███ ░███
███░ ░███ █████ ░███░░█ ░███ ░░░ ░███ ░███ ░███ ░░██████ ░███
███░ ░░███ ░░███ ░███ ░ █ ░███ ░███ ░███ ░███ ░░█████ ░███
███░ ░░█████████ ██████████ █████ █████ █████ █████ ░░█████ █████
░░░ ░░░░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░
Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.
> k8s pod 정보 알려줘
✦ I can get that for you. I'll use the kubectl get pods -A command to list all pods across all namespaces.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ Shell kubectl get pods -A (Listing all Kubernetes pods across all namespaces.) │
│ │
│ NAMESPACE NAME READY STATUS RESTARTS AGE │
│ argocd argocd-application-controller-0 1/1 Running 0 104d │
│ argocd argocd-applicationset-controller-6f9c846c89-72bjt 1/1 Running 0 129d │
│ argocd argocd-dex-server-5c67d5774f-cs222 1/1 Running 0 129d │
│ argocd argocd-notifications-controller-77867675fb-w2t68 0/1 CrashLoopBackOff 81 (35s ago) 129d │
│ argocd argocd-redis-b48fd6b5d-2q9fz 1/1 Running 0 104d │
│ argocd argocd-repo-server-58cf879579-gb5x8 1/1 Running 0 104d │
│ argocd argocd-server-549455bdd9-dmgcq 0/1 CrashLoopBackOff 62 (30s ago) 129d │
│ default fastapi-mm-kospi-6f6f46c45d-k8p8w 1/1 Running 0 129d │
│ kube-flannel kube-flannel-ds-9w9f6 1/1 Running 0 129d │
│ kube-flannel kube-flannel-ds-bk7x6 1/1 Running 0 129d │
│ kube-flannel kube-flannel-ds-cplq9 1/1 Running 0 129d │
│ kube-flannel kube-flannel-ds-xtnr7 1/1 Running 0 129d │
│ kube-system coredns-7785d6c6bc-g2fq7 0/1 CrashLoopBackOff 55 (4m16s ago) 129d │
│ kube-system coredns-7785d6c6bc-w2t5f 1/1 Running 0 104d │
│ kube-system etcd-ygbaek1.cluster.com 1/1 Running 1 130d │
│ kube-system kube-apiserver-ygbaek1.cluster.com 1/1 Running 1 130d │
│ kube-system kube-controller-manager-ygbaek1.cluster.com 1/1 Running 4 130d │
│ kube-system kube-proxy-5dwvn 1/1 Running 0 130d │
│ kube-system kube-proxy-8mffm 1/1 Running 0 130d │
│ kube-system kube-proxy-dlfw8 1/1 Running 0 130d │
│ kube-system kube-proxy-k42vv 1/1 Running 0 130d │
│ kube-system kube-scheduler-ygbaek1.cluster.com 1/1 Running 7 130d │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ It looks like there are a few pods in the argocd and kube-system namespaces that are in a CrashLoopBackOff state. This means they are repeatedly starting and crashing.
Specifically, these pods are:
- argocd-notifications-controller-77867675fb-w2t68
- argocd-server-549455bdd9-dmgcq
- coredns-7785d6c6bc-g2fq7
Would you like me to investigate the logs for one of these crashing pods to figure out why it's failing?
'AI' 카테고리의 다른 글
| Gemini CLI와 Obsidian MCP 서버 연결하기 (0) | 2025.06.28 |
|---|