loading...

27/07/2023

k8s Workflow

================================= Deploy an APP =================================
 
# kubectl get nodes
 
# kubectl create deployment kubernetes-bootcamp –image=gcr.io/google-samples/kubernetes-bootcamp:v1
or # kubectl create deployment kubernetes-bootcamp –image=gcr.io/google-samples/kubernetes-bootcamp:v1 –replicas=2 [for 2 Replicas] 
 
# kubectl get deployments
# kubectl describe deployment kubernetes-bootcamp
 
# kubectl get svc
 
# kubectl get node -o wide
# kubectl get pods –all-namespaces
 
// # curl http://localhost:31730/api/v1/namespaces/default/pods/$POD_NAME/ – Find POD Name
 
 
–> Update Deployment 
 
 
 
================================= Explore the App =================================
 
# kubectl get pods – look for existing Pods
# kubectl describe pods – view what containers are inside that Pod and what images are used to build those containers
# kubectl logs nginx-8f458dc5b-2wz5z – For Logs
# kubectl get pods –all-namespaces
 
# kubectl exec -ti kubernetes-bootcamp-d9b4bdd78-mdsjs — bash –    Get into the Pods
 
// # curl localhost:32750
 
================================= Expose The App =================================
 
–>  Create a new service
# kubectl get pods
# kubectl get services
 
# kubectl expose deployment/kubernetes-bootcamp –type=”NodePort” –port 8080
// # kubectl create service nodeport kubernetes-bootcamp –tcp=81:81
 
# kubectl get services              pods
 
# kubectl describe services/kubernetes-bootcamp
 
# export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}’)
# echo NODE_PORT=$NODE_PORT
 
# curl $(minikube ip):$NODE_PORT
 
–>  Using labels
# kubectl describe deployment
# kubectl get pods -l app=kubernetes-bootcamp
# kubectl get services -l app=kubernetes-bootcamp
 
# export POD_NAME=$(kubectl get pods -o go-template –template ‘{{range .items}}{{.metadata.name}}{{“\n”}}{{end}}’)
# echo Name of the Pod: $POD_NAME
# kubectl label pods $POD_NAME version=v1
 
# kubectl describe pods $POD_NAME
# kubectl get pods -l version=v1
 
–> Deleting a service
# kubectl delete service -l app=kubernetes-bootcamp
 
# kubectl get services
# curl $(minikube ip):$NODE_PORT
# kubectl exec -ti $POD_NAME — curl localhost:32750
 
================================= Scaling Your App =================================
 
# kubectl get deployments
# kubectl get rs
 
# kubectl scale deployments/kubernetes-bootcamp –replicas=4
 
# kubectl get deployments
# kubectl get pods -o wide
# kubectl describe deployments/kubernetes-bootcamp
 
================================= Load Balancing =================================
 
# kubectl describe services/kubernetes-bootcamp
 
# export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}’)
# echo NODE_PORT=$NODE_PORT
 
# curl $(minikube ip):$NODE_PORT
 
================================= Scale Down =================================
 
# kubectl scale deployments/kubernetes-bootcamp –replicas=2
 
# kubectl get deployments
# kubectl get pods -o wide
 
================================= Update the version of the app =================================
 
# kubectl get deployments
# kubectl get pods
# kubectl describe pods
 
# kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
 
# kubectl edit deployments/kubernetes-bootcamp
# kubectl rollout status deployments/kubernetes-bootcamp
 
# kubectl get pods
 
================================= Verify an update =================================
 
# kubectl describe services/kubernetes-bootcamp
 
# export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}’)
# echo NODE_PORT=$NODE_PORT
# curl $(minikube ip):$NODE_PORT
 
# kubectl rollout status deployments/kubernetes-bootcamp
# kubectl describe pods
 
================================= Rollback an update =================================
 
# kubectl rollout history deployments/kubernetes-bootcamp
# kubectl rollout history deployments/kubernetes-bootcamp –revision=2
 
# kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=gcr.io/google-samples/kubernetes-bootcamp:v10
 
# kubectl get deployments
# kubectl get pods
# kubectl describe pods
 
# kubectl rollout undo deployments/kubernetes-bootcamp
# kubectl rollout undo deployments/kubernetes-bootcamp–to-revision=1
 
# kubectl get deployment kubernetes-bootcamp
# kubectl describe deployment kubernetes-bootcamp
 
 
# kubectl get pods
# kubectl describe pods
 
# kubectl rollout pause deployment/kubernetes-bootcamp [Pause Rollout]
 
 
================================= Deploying the Dashboard UI =================================
 
# kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
# kubectl get ns
# kubectl -n kubernetes-dashboard get svc
# kubectl -n kubernetes-dashboard edit svc kubernetes-dashboard
 
 —> Find type: ClusterIP  –> Change to  LoadBalancer
 
 :wq!
 
# kubectl -n kubernetes-dashboard get svc
# nslookup kubernetes-dashboard
 
https://[DNS]
 
— Create Token
# kubectl create serviceaccount dashboard -n default
# kubectl create clusterrolebinding dashboard-admin -n default –clusterrole=cluster-admin –serviceaccount=default:dashboard
# kubectl get secret $(kubectl get serviceaccount dashboard -o jsonpath=”{.secrets[0].name}”) -o jsonpath=”{.data.token}” | base64 –decode
 
—>Copy Token  and paste in the Browser
 
=================================2nd Way =================================
 
https://www.youtube.com/watch?v=bpZzV4GPLks
 
# git clone https://github.com/irsols-devops/kubernetes-dashboard.git
# kubectl apply -f ./kubernetes-dashboard/
# kubectl get pods –all-namespaces -o wide
# kubectl get services –all-namespaces -o wide
# cd kubernetes-dashboard/
# chmod +x get-dash.sh
# ./get-dash.sh
 
 
================================= 3rd Way =================================
 
# w!get https://raw.githubusercontent.com/kubernetes/dashboard/v2.1.0/aio/deploy/recommended.yaml
# mv recommended.yaml kubernetes-dashboard-deployment.yml
# kubectl apply -f kubernetes-dashboard-deployment.yml
# vi service-account-admin.yml
 
# IRSOLS Inc 2019-2021
 
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
 
# vi rbac-clusterRoleBinding-admin.yml
 
# IRSOLS Inc 2019-2020
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
– kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard
 
# kubectl apply -f service-account-admin.yml
# kubectl apply -f rbac-clusterRoleBinding-admin.yml
 
# kubectl get deployments -n kubernetes-dashboard
# kubectl get pods –namespace=kubernetes-dashboard -o wide
# kubectl get services –namespace=kubernetes-dashboard -o wide
# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk ‘{print $1}’)
 
Open up a browser that allows self-signed certificate using webpages ( e.g. Firefox )
and use the node IP:Nodeport combination to access the dashboard . 
 
e.g. https://:<node_port> will be https://10.10.0.4:32005
Posted in k8sTaggs: