In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "Basic Tutorial of Kubernetes Management". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn the "Basic Tutorial of Kubernetes Management" together.
1. Create Container / Pod##
The basic unit of Kubernetes is the Pod, so even if you only have one Container, you have to create a Pod to hold the Container.
apiVersion: v1kind: Podmetadata: name: hello-world # pod resource name, cluster unique spec: # specification of the pod's containers restartPolicy: Never #Run the container once and end the pod containers: - name: hello #just the nickname of the container image: "ubuntu:14.04" # image name, Docker Hub by default command: ["/bin/echo","hello","world"]
Part of the explanation is shown above, where command overrides the Docker container's Entrypoint, Command parameter (corresponding to Docker's Cmd) can be declared using args:
command: ["/bin/echo"] args: ["hello","world"]
Create a pod as follows:
$ kubectl create -f ./ hello-world.yaml --validate #will validate and give WARN, but if there is a problem, it will still create a Pod and output WARN information pods/hello-worldContainer environment variables and variables expand ###apiVersion: v1kind: Podmetadata: name: hello-worldspec: # specification of the pod's contents restartPolicy: Never containers: - name: hello image: "ubuntu:14.04" env: #This is an environment variable - name: MESSAGE value: "hello world" command: ["/bin/sh","-c"] # Kubernetes does not run shell automatically, you need to specify it manually args: ["/bin/echo \"${MESSAGE}\""] #This is the environment variable expansion used
Without a shell our environment variables can still be expanded with $(ENVVAR). For example:
command: ["/bin/echo"] args: ["$(MESSAGE)"]
##2. View Pod Status ##
$ kubectl get podsNAME READY STATUS RESTARTS AGEhello-world 0/1 Pending 0 0s
The status is as follows:
unscheduled -first create POD, not select node to run Pod, then schedule immediately
scheduled - Pod has been Scheduled, ready to pull mirror on target node
running -container boot from mirror succeeded, READY column indicates how many containers are OK
ExitCode:0 -exit normally, container is no longer running
##3. Delete Pod##
$ kubectl delete pod hello-worldpods/hello-world
or resource/name format to delete
$ kubectl delete pods/hello-worldpods/hello-world
Both the container and its output logs are deleted.
##4. Creating Replication Controller## Replication Controller ensures that the correct number of replicas of the pod is running, hereinafter referred to as RC/rc. Here are 2 copies of Nginx:
apiVersion: v1kind: ReplicationController #is no longer Podmetadata: name: my-nginxspec: replicas: 2 template: #This is a PodTemplateSpec, which declares the Pod specification below metadata: #Pod names do not need to be declared because they are automatically generated by RC labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 #Open Port
##5. Delete Replication Controller##
$ kubectl delete rc my-nginxreplicationcontrollers/my-nginxLabel
Kubernetes uses Lables to classify and identify different sets of resources, such as Pods and Replication Controllers. We can read pods and rc with app key and nginx value:
$ kubectl get pods -L appNAME READY STATUS RESTARTS AGE APPmy-nginx-afv12 0/1 Running 0 3s nginxmy-nginx-lg99z 0/1 Running 0 3s nginx$ kubectl get rc my-nginx -L appCONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS APPmy-nginx nginx nginx app=nginx 2 nginx
You can also use golang templates to get information
$ kubectl get rc my-nginx -o template --template="{{.spec.selector}}"map[app:nginx]6. Create Service##
Below is a yaml file for a service. Services are loosely coupled to pods. Can be combined freely. Once created, a clusterIP is assigned, and there is a simple load balancer for this clusterIP.
apiVersion: v1kind: Servicemetadata: name: nginxsvc labels: app: nginxspec: ports: - port: 80 #The address accessed is http://clusterIP:80/ protocol: TCP selector: #means handled by pod of app=nginx app: nginx
There can be multiple endpoints behind a Service to process.
$ kubectl describe svc nginxsvcName: nginxsvcNamespace: defaultLabels: app=nginxSelector: app=nginxType: ClusterIPIP: 10.0.116.146Port: 80/TCPEndpoints: 10.245.0.14:80,10.245.0.15:80Session Affinity: NoneNo events.$ kubectl get epNAME ENDPOINTSnginxsvc 10.245.0.14:80,10.245.0.15:80 Thank you for reading, the above is the content of "Kubernetes management basic tutorial", after learning this article, I believe that everyone has a deeper understanding of Kubernetes management basic tutorial this problem, the specific use of the situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.