kubernate command - amresh087/newronaRepos GitHub Wiki
Kubernate command
minikube===>>Launch A Single Node Cluster
kubectl apply -f mysql-pv.yaml
kubectl apply -f mysql-deployment.yaml
kubectl apply -f mysql-service.yaml
kubectl apply -f loan-demo-service.yaml
kubectl delete deployment,svc mysql
kubectl delete pvc mysql-pv-claim
kubectl delete pv mysql-pv-volume
kubectl delete secret mysql-secret
Show all pods
kubectl get pods --all-namespaces -o jsonpath="{.items[].spec.containers[].image}" -l app=mysql
describe pod by id
kubectl describe pods ${mysql-68579b78bb-4l7h6}
mysql storage
kubectl apply -f mysql-storage.yaml
deployment for loan service
kubectl apply -f loan-demo-deployment.yaml
delete for loan service
kubectl delete deployment,loan-demo-app
create deployment
kubectl create deployment loan-demolatest --image=renuellen2018/renurepo:loan-demolatest
open mysql command promt
kubectl exec --stdin --tty mysql-68579b78bb-hl2j5 -- /bin/bash
build tag for docker image
docker build --tag=loan-demo:latest .
run docker images
docker run -p 8887:8080 book-rest:latest
build tag for docker image
docker tag loan-demo:latest renuellen2018/renurepo:loan-demolatest
push docker images in repo of dockerhub
docker push renuellen2018/renurepo:loan-demolatest
deployment service on kubernate/minikube
kubectl create deployment book-app --image=renuellen2018/renurepo:booklatest
kubectl expose deployment book-app --name=book-app-service --type=NodePort --port 80 --target-port 2022
minikube service list
minikube start --driver=hyperv
minikube version
kubectl cluster-info
kubectl get nodes
kubectl create deployment first-deployment --image=katacoda/docker-http-server
kubectl get pods
kubectl expose deployment first-deployment --port=80 --type=NodePort
export PORT=$(kubectl get svc first-deployment -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}')
minikube addons enable dashboard
kubectl apply -f /opt/kubernetes-dashboard.yaml
kubectl get pods -n kubernetes-dashboard -w
//==========================Launch a multi-node cluster using Kubeadm======================
Initialise Master
kubeadm init --token=102952.1a7dd4cc8d1f4cc5 --kubernetes-version $(kubeadm version -o short)
after run above command
sudo cp /etc/kubernetes/admin.conf $HOME/ sudo chown (id -g) $HOME/admin.conf export KUBECONFIG=$HOME/admin.conf
Deploy Container Networking Interface (CNI)---> There are multiple plugin for network
here we are going to install WeaveWorks
cat /opt/weave-kube.yaml
This can be deployed using kubectl apply.
kubectl apply -f /opt/weave-kube.yaml
kubectl get pod -n kube-system
Join Cluster Once the Master and CNI has initialised,
kubeadm token list.
Now the below command run in another terminal then its become child
kubeadm join --discovery-token-unsafe-skip-ca-verification --token=102952.1a7dd4cc8d1f4cc5 172.17.0.24:6443
View Nodes
kubectl get pods
///in child
Once running, you can see the Docker Container running on the node.
docker ps | grep docker-http-server
Deploy Dashboard Kubernetes has a web-based dashboard UI giving visibility into the Kubernetes cluster.
cat <<EOF | kubectl create -f - apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kube-system apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects:
kind: ServiceAccount name: admin-user namespace: kube-system EOF Once the ServiceAccount has been created, the token to login can be found with:
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLW5kZjRiIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4NzMwYzVlMy02Yjc2LTExZWMtYjE3Zi0wMjQyYWMxMTAwMTgiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.Q0Sog2guwjZuVpK0huDZHSQhNzuuEeIdsS7u5KujZ5Fd-zWl0cIIe27jE4j_vubIGJKoRj62bBqTnXAIMBSlGDqXtjMDGdOn72a5UPOY5yTwXL4fvug8CnWEkxIsm2eX-4SGLND3g-MLFeHz-861RvjjnY8nhS113ekUZpIB-IgKrQUPj7wns9ZWsEVokdjEh839Xb_1GRLhrddFgA2rx0GdhJfjVQ0Fi2V1mgFLrHaPJroLOA1vAVhmuLp0mcyR8ugQ9a1Iut8fhEHgzGY9OBtTZs5A1s0dYKRUY7XYTT4xOX3cadTz0sut97EM2SnLkNvBLJsqXhvOMu_pqaRHDw
//=======================================Deploy Containers Using Kubectl==========
kubectl run http --image=katacoda/docker-http-server:latest --replicas=1
kubectl get deployments
kubectl describe deployment http
expose the container port 80 on the host 8000 binding to the external-ip of the host.
With kubectl run it's possible to create the deployment and expose it as a single command.
kubectl run httpexposed --image=katacoda/docker-http-server:latest --replicas=1 --port=80 --hostport=8001
Under the covers, this exposes the Pod via Docker Port Mapping. As a result, you will not see the service listed using
kubectl get svc
To find the details you can use
docker ps | grep httpexposed
Scale Containers
With our deployment running we can now use kubectl to scale the number of replicas.
kubectl scale --replicas=3 deployment http
kubectl get pods
Once each Pod starts it will be added to the load balancer service. By describing the service you can view the endpoint and the associated Pods which are included.
//=========================================Deploy Containers Using YAML======================
Copy the following definition to the editor. The definition defines how to launch an application called webapp1 using the Docker Image katacoda/docker-http-server that runs on Port 80.
apiVersion: apps/v1 kind: Deployment metadata: name: webapp1 spec: replicas: 1 selector: matchLabels: app: webapp1 template: metadata: labels: app: webapp1 spec: containers: - name: webapp1 image: katacoda/docker-http-server:latest ports: - containerPort: 80
This is deployed to the cluster with the command
kubectl create -f deployment.yaml
kubectl get deployment
kubectl describe deployment webapp1
Create Service
Kubernetes has powerful networking capabilities that control how applications communicate. These networking configurations can also be controlled via YAML.
apiVersion: v1 kind: Service metadata: name: webapp1-svc labels: app: webapp1 spec: type: NodePort ports:
port: 80 nodePort: 30080 selector: app: webapp1 kubectl create -f service.yaml
kubectl get svc
kubectl describe svc webapp1-svc
curl host01:30080
Scale Deployment
Updates to existing definitions are applied using kubectl apply. To scale the number of replicas, deploy the updated YAML file using
kubectl apply -f deployment.yaml
kubectl get deployment
kubectl get pods
curl host01:30080
//=======================Deploy Guestbook Web App Example============