govc로 vCenter 로그인
govc
govc는 vSphere CLI이다. govmomi라는 go용 vSphere API 라이브러리가 있고 이를 이용하여 개발된 CLI가 govc이다. vSphere용 CLI이므로 vCetner와 ESXi를 다 컨트롤 할 수 있다. 설치부터 로그인까지는 해당 페이지를 확인하면 굿.
docker file
아래 경로 참조 https://github.com/vmware/govmomi/tree/master/govc
docker hub의 govc 이미지 경로
https://hub.docker.com/r/vmware/govc
설치
공식 튜토리얼에도 docker설치가 가장 위에 올라와 있다. govc는 이름처럼 go위에서 돌아가므로 go를 설치하고, govc를 설치해야하므로 아래 docker 파일을 쓰는게 마음이 편하지 않을까. https://github.com/vmware/govmomi/blob/master/Dockerfile.govc
로그인
심플하게 아이디/패스워드로 로그인하려면 아래와 같은 환경변수를 잡아주면 된다.
vCenter URL은 다음과 같이 설정하고,
GOVC_URL: URL of ESXi or vCenter instance to connect to.The URL scheme defaults to https and the URL path defaults to /sdk. This means that specifying user:pass@host is equivalent to https://user:pass@host/sdk.If username or password includes special characters like \, # or : you can use GOVC_USERNAME and GOVC_PASSWORD to have a simple GOVC_URLWhen using govc against VMware Workstation, GOVC_URL can be set to "localhost" without a user or pass, in which case local ticket based authentication is used.
아이디, 암호는 다음과 같이 설정하자
GOVC_USERNAME: USERNAME to use if not specified in GOVC_URL.GOVC_PASSWORD: PASSWORD to use if not specified in GOVC_URL.
vcenter(혹은 ESXi)에 인증서 설치가 제대로 되어 있지 않다면, TLS 인증서 경고를 무시하도록 설정하자
GOVC_INSECURE: Disable certificate verification.
위 네변수를 정리해보면
export GOVC_URL=https://vcenterurl/sdkexport GOVC_USERNAME=vcenteridexport GOVC_PASSWORD=vcenterpasswordexport GOVC_INSECURE=1
정도가 되겠다.
확인
govc 도커 이미지를 땡겨서 vcenter에 로그인 후 govc ls를 땡겨보자.
$ docker run -e GOVC_URL=https://vcenterid:vcenterpasswd@vcenterurl -e GOVC_INSECURE=true --rm -it -vmware/govc /govc ls
명령
쓸 명령은 다음과 같다.
vm 업그레이드
vm의 하드웨어 버전을 15로 업그레이드한다. 하드웨어 버전 업그레이드는 vm을 끈 상태에서만 가능하다.
govc vm.upgrade -verion=15 -vm 'fullpathOfVM'
참조
[1] https://cloud-provider-vsphere.sigs.k8s.io/tutorials/kubernetes-on-vsphere-with-kubeadm.html [2] govc git repository : https://github.com/vmware/govmomi/tree/master/govc [3] govc docker image : https://hub.docker.com/r/vmware/govc