Skip to content

yumaeda/kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 

Repository files navigation

kubernetes

Preparations

Install packages

brew install \
  helm \
  kubectl \
  kubectx \
  kustomize

Enable container.googleapis.com

gcloud services enable container.googleapis.com

 

Create GKE cluster

Set environment variables

export PROJECT_ID=xxxx
export REGION=asia-northeast1 &&
export ZONE=asia-northeast1-b &&
export CLUSTER_NAME="prod-$REGION-sakabas"

Execute below command

gcloud container clusters create \
  --preemptible \
  --project=${PROJECT_ID} \
  --machine-type=e2-small \
  --num-nodes=2 \
  --disk-size=10 \
  --network=sakabas-tokyo-vpc \
  --subnetwork=subnet-asia-northeast-172 \
  --zone ${ZONE} \
  --cluster-version latest \
  ${CLUSTER_NAME}

Get a list of GKE cluster

gcloud container clusters list

Populate kubeconfig file (Add a new kubectl context)

gcloud container clusters get-credentials ${CLUSTER_NAME} --region ${ZONE} --project ${PROJECT_ID}

Show list of kubectl contexts

kubectx

Show namespace for the current kubectl context

kubens -c

Switch kubectl context

kubectx ${KUBECTL_CONTEXT}

Delete GKE cluster

gcloud container clusters delete ${CLUSTER_NAME}

 

Trouble-shooting

Increase the number of nodes

  • Create a new node-pool with more nodes
gcloud container node-pools create ${NEW_POOL_NAME} \
  --cluster ${CLUSTER_NAME} --zone ${ZONE} \
  --machine-type=e2-small --num-nodes=3 \
  --disk-size=10 --preemptible
  • Delete the old node-pool
gcloud container node-pools delete ${OLD_POOL_NAME} --cluster ${CLUSTER_NAME} --zone ${ZONE}

Execute command within pods

kubectl exec --stdin --tty ${POD_NAME} -- /bin/sh

Show logs for the pod

kubectl logs ${POD_NAME}

See current resource usage

kubectl top pod --all-namespaces

Delete the current pod

kubectl delete pod ${POD_NAME}

Delete all pods

kubectl delete --all pods --all-namespaces

 

Misc

kubectl get pod --all-namespaces

Port-forward service to localhost

kubectl port-forward svc/web 8080:8080

Rollout restarted Deployment

kubectl rollout restart deployment/web
  • Old pod is replaced by new pod.

 

Reference

About

Describes how to use kubernetes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published