Kubernetes notes at the beginning of the demo experience

Source: Internet
Author: User
Tags k8s

This article starts with my public number clouddeveloper, and you are welcome to join me in learning cloud computing.

From the previous article we know that Kubernetes born in the borg,borg of Google in the beginning of the birth of Kubernetes has been in the internal battle of Google more than 10 years, and does not say its history has a long tradition, it is from Google that talented engineers hand, Know that it is difficult to learn.

For this kind of technology with a certain learning threshold, the best way to get started is to play first, if you just start to indulge in those theories, it is easy to get started to give up.

Fortunately, Google has taken this into account, the official documentation provides a very small demo, the little, perfectly formed, this demo basically covers the basic concept of k8s, through which can easily build a k8s cluster, play k8s, we now go to play. (PS: The concepts mentioned below, we will discuss in detail later, do not understand can temporarily skip)

Open it:
Kubernetes.io/docs/tutorials/kubernetes-basics

The 6 steps to be illustrated are as follows:

    1. Create a k8s cluster
    2. Deploy Apps
    3. Explore the APP
    4. Access the APP
    5. APP Elastic Scaling
    6. Update APP

Before you start each step, get to know something-- minikube . As the name implies, this is a mini version of the k8s, a lightweight k8s implementation, for the normal learning experience, use it can achieve and use the same effect as k8s. Its deployment is simple enough, all-in-one, a cluster has only one node, k8s all components are deployed on this node.

Users can also use the Web UI and the Minikube CLI to manage k8s clusters, such as: Start, stop, delete, get status, and so on. The official demo is done using the Minikube CLI.

Not much to say, below we will begin to experience the journey of the next k8s.

The first step: Create a k8s cluster

The interactive interface input minikube start creates a k8s cluster that is created on a single VM and k8s all components are running on this VM.

Next, we can use the k8s command-line tool kubectl to manipulate the cluster.

kubectl versionTo view the version number of the k8s:

See two version, referring to the version of client version Kubectl, server version is the version of k8s.

kubectl get nodesGet the number of cluster nodes:

You can see that this demo has only one node, which is the VM created earlier. statusYes ready , it means that the node is ready to deploy the APP.

Step Two: Deploy an APP

Execute command:

kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080

The deployment of an APP was completed.

Where --image you specify the Docker image of the app, --port set the port for the app's outbound service, kubectl run download the image, and create deployment the app based on deployment. Deployment is like the app's manual, which guides how to create and maintain apps. After the APP is created, run in the Docker container, using kubectl get deployments the information that you can view deployment.

Step Three: Explore the APP

After creating the deployment in the previous step, the pod is then created to run the app container, K8s uses the pod to manage the container resources, one pod can contain one or more containers, and in this case, one pod has only one app container. Use to kubectl get pods view the current Pod information.

More detailed information is used for kubectl describe pods viewing.

The Kubectl tool is helpful for troubleshooting, and the following are some of the more common commands:

    • kubectl Get -list resources
    • Kubectl describe -show details about a resource
    • kubectl logs -log of containers in the output Pod
    • kubectl exec -execute commands in Pod container
Fourth Step: access the APP

By default, all pods are accessible only within the cluster, where each pod has an IP and port that can be accessed directly between pods. External want to access Pod, need to expose the port, execute the following command:

kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080

Map the container's port (8080) to the port of the node.

Performs a view of the kubectl get services port to which the node is mapped.

You can see that port 8080 of the container is already mapped to the 31915 port of the node. The NodeIP:Port container inside the Pod can be accessed by external means, as follows:

serviceIs the further abstraction of the pod in k8s, which is the entrance to the external access pod. If you think of the k8s cluster as an organization, then the service is the interface person for the organization, why the service is needed, and this is what is left behind, where you can temporarily interpret it as a port mapping.

Fifth Step: elastic scaling for apps

To accommodate high availability, pods can be automatically expanded and scaled. By default, the Pod runs only one copy, which is defined by deployment and can be kubectl get deployments increased or decreased by viewing the number of replicas kubectl scale deployments/app --replicas=num .

For example, increase the number of replicas to 4:

See the number of pods also increased to 4.

Reduce the number of replicas to 2:

See two copies of the display terminating, indicating that it is aborting, after a period of time to see only two.

For multiple replicas, access to the APP is load balanced, as follows:

Seeing each request access falls on a different Pod, this function is done by the service.

Sixth step: Update APP

The image version used by the current APP is v1 and needs to be upgraded to V2 to execute the following command:

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2

See the upgrade process is to abort the previous 4 copies, and then re-open 4 copies.

If you fall back to the V1 version, simply execute the following command:

kubectl rollout undo deployments/kubernetes-bootcamp

At this point, we have through the official demo experience a k8s of the function and use of the method, below I will continue to learn the k8s of their own notes to organize, share to you, hope to help you. If possible, please forward to share, so that more people also participate in.

Finally, or continue to send books, container network expert Nu Bongfei wrote the "k8s Guide" ebook, if you need to reply to the background "k8s" (before reply will not have to reply). If you need to add Group learning to reply to "add group".

More dry Goods Welcome to the public number Clouddeveloper (a collection of cloud computing size of the public number) view:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.