Verified Commit 44c2cc4e authored by Xueshan Feng's avatar Xueshan Feng
Browse files

Create kube-addons.mk. Moved addons to this file.

parent 544bb4fe
Loading
Loading
Loading
Loading
+98 −0
Original line number Diff line number Diff line


################################################################################
## kube-addons.mk
# Makefile targets useful for adding system-wide addons
################################################################################

KUBECONFIG := ${HOME}/.kube/${CLUSTER_NAME}
AWS_PROFILE := ${AWS_PROFILE}
ifndef CLUSTER_NAME
	missing_vars := ${missing_vars} CLUSTER_NAME
endif

ifndef AWS_PROFILE
	missing_vars := ${missing_vars} AWS_PROFILE
endif

ifndef TILLER_IMAGE
	TILLER_IMAGE := gcr.io/kubernetes-helm/tiller:v2.9.1
endif

ifndef TEMPLATES
	missing_vars := ${missing_vars} TEMPLATES
endif


###################################
### Kubernetes dashboard provision
###################################
.PHONY: dashboard
dashboard: KUBERNETES_DASHBOARD=https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
dashboard: config-kube ## Start dashboard
	@echo $$HOME/.kube/${CLUSTER_NAME}
	@kubectl apply -f ${TEMPLATES}/dashboard/role-binding.yaml
	@kubectl apply -f ${TEMPLATES}/dashboard/service-account.yaml
	@kubectl apply -f ${KUBERNETES_DASHBOARD}
	# Patch dashboard token ttl from 15 minutes to 24 hours.
	@kubectl patch deployment kubernetes-dashboard --patch "$$(cat ${TEMPLATES}/dashboard/patch-token-ttl.yaml)" -n kube-system

.PHONY: delete-dashboard
delete-dashboard: kill-ui ## Delete dashboard
	@kubectl delete --kubeconfig=$$HOME/.kube/${CLUSTER_NAME} -f ${KUBERNETES_DASHBOARD} --ignore-not-found

.PHONY: ui
ui: dashboard ## kubectl proxy and open dashboard ui
	kubectl --kubeconfig=$$HOME/.kube/${CLUSTER_NAME} proxy -p 8001 &> /dev/null &
	@while ! kubectl get pods -n kube-system -o json -l k8s-app=kubernetes-dashboard | jq .items'[]'.status.containerStatuses'[]'.ready | grep -q true; \
	do \
		echo Waitting for UI ; \
		sleep 10 ; \
	done
	@echo
	@echo To access endpoint of dashboard local proxy, go to:
	@echo http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
	@echo
	@echo "Please 'make kill-ui' to close kube proxy connection"

.PHONY: admin-token
admin-token: TOKEN_NAME=$$(kubectl get sa -n kube-system eks-admin -o json | jq -r '.secrets[].name')
admin-token: ## Get admin-token to login to dashboard
	@kubectl describe secret -n kube-system ${TOKEN_NAME} | grep ^token:

.PHONY: kill-ui
kill-ui:  ## Close Kube dashboard connection
	@if pgrep -f 8001 &> /dev/null ; \
	then \
	  echo Killed Proxy on port 8001 ; \
		kill $(shell pgrep -f 8001) ; \
	fi

########################
## Tiller agent for helm
#########################
.PHONY: tiller
tiller: ## install/upgrade helm tiller
	@-kubectl create serviceaccount --namespace kube-system tiller || true
	@-kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
	#kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
	helm init --service-account tiller --upgrade --tiller-image ${TILLER_IMAGE}
.PHONY: destroy-tiller
destroy-tiller: #config-kube ## destroy helm tiller
	kubectl delete serviceaccount --namespace kube-system tiller
	kubectl delete clusterrolebinding tiller-cluster-rule
	kubectl -n "kube-system" delete deployment tiller-deploy

##############################
## Heapster to collect metrics
##############################
.PHONY: heapster
heapster: ## Install heapster
	helm install --name heapster --namespace kube-system --set rbac.create=true stable/heapster
PHONY: upgrade-heapster
upgrade-heapster: ## Update heapster
	helm upgrade heapster --set rbac.create=true stable/heapster
.PHONY: heapster
destroy-heapster: ## Install heapster
	helm del heapster
+0 −26
Original line number Diff line number Diff line
@@ -15,10 +15,6 @@ ifndef AWS_PROFILE
	missing_vars := ${missing_vars} AWS_PROFILE
endif

ifndef TILLER_IMAGE
	TILLER_IMAGE := gcr.io/kubernetes-helm/tiller:v2.9.1
endif

.PHONY: describe-cluster
describe-cluster: ## Check EKS cluster settings
	@aws eks describe-cluster --cluster-name ${CLUSTER_NAME} --query cluster
@@ -29,28 +25,6 @@ list-clusters: ## show all EKS clusters
get-images: ## List all images running in the cluster
	@kubectl get pods --all-namespaces -o jsonpath="{..image}" | tr -s '[[:space:]]' '\n' | sort | uniq -c

.PHONY: tiller
tiller: ## install/upgrade helm tiller
	@-kubectl create serviceaccount --namespace kube-system tiller || true
	@-kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
	#kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
	helm init --service-account tiller --upgrade --tiller-image ${TILLER_IMAGE}
.PHONY: destroy-tiller
destroy-tiller: #config-kube ## destroy helm tiller
	kubectl delete serviceaccount --namespace kube-system tiller
	kubectl delete clusterrolebinding tiller-cluster-rule
	kubectl -n "kube-system" delete deployment tiller-deploy

.PHONY: heapster
heapster: ## Install heapster
	helm install --name heapster --namespace kube-system --set rbac.create=true stable/heapster
PHONY: upgrade-heapster
upgrade-heapster: ## Update heapster
	helm upgrade heapster --set rbac.create=true stable/heapster
.PHONY: heapster
destroy-heapster: ## Install heapster
	helm del heapster

.PHONY: check-images ## check all running images
check-images: ## check all running images
	kube-images-report.sh