Showing posts with label kubectl. Show all posts
Showing posts with label kubectl. Show all posts

Sunday, March 14, 2021

Kubernetes: kubectl config management.

 Config kubectl

Script to set current contexts:

clear


production="true"


[[ $0 != $BASH_SOURCE ]] && contextName=$BASH_SOURCE || contextName=$0


contextName=${contextName##*/}


export KUBECONFIG=~/.kube/config.${contextName}


kubectl config use-context ${contextName}


#starts 38;5; for the foreground and 48;5; for the background, then the color number


if [ $production == "true" ]; then

  export PS1="\e[38;5;016;0;48;5;166m\u@\H:\w - \e[5m$contextName\e[25m $ "

else

  export PS1="\e[38;5;012;48;5;015m\u@\H:\w - $contextName $ "

fi

  

kubectl config get-contexts

Monday, September 28, 2020

Kubectl Cheatsheet

$ kubectl get svc --all-namespaces  | awk '{{gsub(/,/, ";", $6)}; a = ""; for (i = 1 ; i <= NF -1 ; i++) a = a $i "," ; print substr(a, 1, length(a)-1)}'

Monday, January 6, 2020

Kubernetes: Deploy Application

https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app

git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples
cd kubernetes-engine-samples/hello-app
export PROJECT_ID=feipoc

Build and publish docker image

docker build -t feijiangnan/${PROJECT_ID}/hello-app:v1 .

docker push feijiangnan/${PROJECT_ID}/hello-app:v1

 docker push feijiangnan/feipoc:v1
The push refers to repository [docker.io/feijiangnan/feipoc]
29696f6ceea7: Pushed
6b27de954cca: Pushed
v1: digest: sha256:46c0116c6a4f0e90350e9dabed603d28c7c9775bd354c38eac18ccc9c99d502c size: 739

Create Deployment

kubectl create deployment hello-web --image=docker.io/feijiangnan/feipoc:v1

Delete Deployment

kubectl delete deployment hello-web
kubectl create deployment hello-web --image=docker.io/feijiangnan/feipoc:v1

Validate Deployment

kubectl describe pod hello-web-848b6b9bd-4vbz5
kubectl get pod

kubectl expose deployment hello-web --type=LoadBalancer --port 80 --target-port 8080

Scale Out Deployment

kubectl scale deployment hello-web --replicas=3

Display the prior Deployments

kubectl rollout history deployment hello-web

Restore last Deployment

kubectl rollout undo deployment hello-web

Tuesday, December 31, 2019

Kubernetes Nodes: Ready,SchedulingDisabled

Check nodes status

# kubectl get nodes
NAME       STATUS                     ROLES    AGE   VERSION
srv2020   Ready                      master   24h   v1.17.0
srv2021   Ready,SchedulingDisabled   <none>   23h   v1.17.0

Remove a node from service

# kubectl drain srv2021

Put a node back to service

# kubectl uncordon srv2021
node/srv2021 uncordoned