Neo Anderson's Blog

K8s初始入门

字数统计: 499阅读时长: 2 min
2018/07/24
loading

kubernetes-bootcamp

The goal of this interactive scenario is to deploy a local development Kubernetes cluster using minikube

  • Create a Cluster

    • Cluster up and running
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    $ minikube version
    minikube version: v0.25.0


    $ minikube start

    There is a newer version of minikube available (v0.28.1). Download it here:
    https://github.com/kubernetes/minikube/releases/tag/v0.28.1

    To disable this notification, run the following:
    minikube config set WantUpdateNotification false
    Starting local Kubernetes v1.9.0 cluster...
    Starting VM...
    Getting VM IP address...
    Moving files into cluster...
    Setting up certs...
    Connecting to cluster...
    Setting up kubeconfig...
    Starting cluster components...
    Kubectl is now configured to use the cluster.
    Loading cached images from config file.

    $ kubectl version
    Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"", Minor:"", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2018-01-26T19:04:38Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"linux/amd64"}

    • Cluster details
    1
    2
    3
    4
    5
    6
    7
    $ kubectl cluster-info
    Kubernetes master is running at https://172.17.0.41:8443

    $ kubectl get nodes
    NAME STATUS ROLES AGE VERSION
    host01 Ready <none> 4m v1.9.0

  • Deploy An App

    • Kubernetes Deployments
      This provides a self-healing mechanism to address machine failure or maintenance.

    arktankche

    • Interactive Tutorial - Deploying an App
    helm
    1
    2
    3
    kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080 //测试demo
    kubectl run nginx-php-fpm --image=richarvey/nginx-php-fpm --port=80 //nginx-php-fpm 镜像
    kubectl get deployments // 获取当前已经部署的应用列表
  • Explore Your App

    • Viewing Pods and Nodes

    Pods are the atomic unit on the Kubernetes platform
    Containers should only be scheduled together in a single Pod if they are tightly coupled and need to share resources such as disk.
    Pods overview

    Node overview

    1
    2
    3
    4
    5
    kubectl get pods  //获取当前所有pods

    kubectl describe pods //描述当前pods
    kubectl exec -ti $POD_NAME bash //进入docker 交互

  • Expose Your App Publicly

    • Using a Service to Expose Your App

    A Kubernetes Service is an abstraction layer which defines a logical set of Pods and enables external traffic exposure, load balancing and service discovery for those Pods.

    Services and Labels

    helm
    1
    2
    3
    4
    kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
    kubectl describe services/kubernetes-bootcamp
    kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}' //输出开放的端口号

  • Scale Your App

    • Running Multiple Instances of Your App
      Scaling Overview01
      Scaling Overview02
    helm
    1
    Scaling is accomplished by changing the number of replicas in a Deployment //通过更改部署中的副本数来完成扩展
CATALOG