当前位置:网站首页>[cloud native learning notes] kubernetes practice command

[cloud native learning notes] kubernetes practice command

2022-06-24 21:14:00 The night owl of the second dimension


Preface


I introduced some information about k8s Basic theoretical knowledge of cluster , This time, we will deepen our understanding of theory in combination with practice .


One 、Kubernetes install

Given the limitations of the learning environment , This installation Minikube.minikube It's local Kubernetes, Focus on making Kubernetes Easy to learn and develop .k8s Commonly used in linux In the system , Because it is only used for learning and familiarity k8s command , This time, it will be based on the system used , install windows Version of Minikube. The official tutorial

  1. download .exe Installation package Installation .
  2. Add the installation directory to the system environment variable Path. The default installation directory is C:\Program Files\Kubernetes\Minikube
  3. Need to be advanced Install well docker, The same is windows Version and launch .
  4. stay cmd Run command in minikube start To initialize and start minikube.
  5. Can be used later minikube stop To stop the cluster

Minikube Will start a virtual machine ,Kubernetes The cluster runs on a virtual machine .minikube with dashboard service , For visual monitoring and viewing minikube situation . In the new cmd Running on the terminal minikube dashboard To activate the function .

Two 、 Cluster interaction

adopt kubectl Command can be root Kubernetes Interaction .kubectl The common format of the command is :kubectl action resources . The function is to perform the specified action on the specified resource . Execute the run command kubectl You can get all the information about resources and actions . Official documents There are also detailed instructions .

1、 Check the cluster status

see kubectl Is the installation successful , It is generally reflected by the view version :

kubectl version

You'll see... At the same time client and server Two version numbers . among ,client Corresponding kubectl Version of ,server Corresponding Master Installed on Kubernetes Version of .

View the details of the cluster :kubectl cluster-info
View cluster node:kubectl get nodes

2、 About deploying applications

adopt kubectl run The command can run the specified image in the cluster . For deploying images , In terms of launching applications , What is actually commonly used is not kubectl run, It is kubectl creat perhaps kubectl apply.apply Use relatively more .

kubectl creat: Create a new resource with configuration , Since the resource name should be unique in the namespace , When repeated , Will report a mistake .
kubectl apply: Apply configuration to resources . If the resource does not exist , Create a new resource . When repeated , If the configuration is modified, the resource will be updated , Otherwise, the resources will not change .

Use here kubectl run Run the application deployment :

kubectl run kubernetes-bootcamp --image=jocatalin/kubernetes-bootcamp:v1 --port=8080

Check pod state running Success after :

kubectl get pod -A | grep kubernetes-bootcamp
default                kubernetes-bootcamp                         1/1     Running   0             28m

Applications are deployed in clusters , If the application services are not exposed outside the cluster , So use url You can't access the service directly .
Direct access will prompt to reject the link :

curl http://localhost:8001/version
curl: (7) Failed to connect to localhost port 8001 after 2203 ms: Connection refused

kubectl proxy Command can create a proxy , Forward communications to a cluster wide private network . The agent can pass control-C End , And no output will be displayed at run time , You can run the agent in other terminal windows .
Revisit :

curl http://localhost:8001/version
{
    
  "major": "1",
  "minor": "23",
  "gitVersion": "v1.23.1",
  "gitCommit": "86ec240af8cbd1b60bcc4c03c20da9b98005b92e",
  "gitTreeState": "clean",
  "buildDate": "2021-12-16T11:34:54Z",
  "goVersion": "go1.17.5",
  "compiler": "gc",
  "platform": "linux/amd64"
}

Here, you can access our deployed applications through the forwarding provided by the cluster :

$ curl http://localhost:8001/api/v1/namespaces/default/pods/kubernetes-bootcamp/proxy/
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp | v=1

3、 ... and 、 About the characteristics of the cluster

  • Automatic load balancing : Automatically assign requests to each pod To respond to .
  • Service scaling : Update applied pod Copy number
  • Service version upgrade : The image used by the update application is used for upgrading .
    have access to kubectl rollout status deployments/xxx Check out the upgrade process , Is to replace each... One by one pod.
    have access to kubectl rollout undo deployments/xxx Quickly go back to the previous version .
  • Common commands for troubleshooting cluster resources are :
    kubectl get : List resources
    kubectl describe : Show details about the resource
    kubectl logs : Print log
    kubectl exec : Go to the container and execute the command
原网站

版权声明
本文为[The night owl of the second dimension]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211317394469.html