Kubernetes basics

basic command

  • Initialize the cluster
    sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.33.242 --kubernetes-version stable-1.11 -v 10
    
  • View the logs
    kubectl logs -f kubernetes-dashboard-767dc7d4d-f8r8l -n kube-system
    
  • Forward the port
    kubectl port-forward pod/guids-796989bbbb-qj2nl 9000:9000
    
  • Expose the port (By NodePort)
    kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
    
    kubectl expose deployments hello-world
    
  • Label a pod
    kubectl label pod guids-796989bbbb-qj2nl app=guids
    
    kubectl get pods -l app=guids
    
  • Tear down the cluster
    kubectl drain neo --delete-local-data --force --ignore-daemonsets
    kubectl delete pod,service baz foo
    
  • Re-add the node
    service kubelet restart
    kubectl uncordon neo
    
  • Various get
    kubectl get nodes
    kubectl get pods
    kubectl get services
    kubectl get deployments -o wide
    kubectl get all -n kube-system
    kubectl get storageclass
    kubectl api-resources
    
  • Describe
    kubectl describe services guids
    
  • Create a deployment
    kubectl run hello-world --replicas=2 --labels="run=load-balancer-example" --image=neocxf/hello-world  --port=8080
    
  • View the pod name
    export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
    
  • Configure default storage class
    kubectl patch storageclass standard -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
    
    kubectl create -f https://k8s.io/examples/pods/storage/pv-volume.yaml
    kubectl get pv task-pv-volume
    kubectl create -f https://k8s.io/examples/pods/storage/pv-claim.yaml
    kubectl get pvc task-pv-claim
    
  • How to set a pv and pvc
    kubectl scale sts web --replicas=2
    kubectl delete pvc www-web-2
    kubectl patch pv task-pv-volume3 # delete pvc in pv yaml
    kubectl get pv                   # now we have an available pv
    
  • Print the join command
    kubeadm token create --print-join-command
    
  • ConfigMap
    kubectl create configmap example-redis-config --from-file=redis-config
    kubectl get configmap example-redis-config -o yaml
    
  • Redis-Master-Slave-Frontend deploy

2. How Kubernetes work

2.1 Main components

kubernetes-flow

10 comments

Leave a Reply

Your email address will not be published. Required fields are marked *