Spring Cloud: Kubernetes deployment management k8s Foundation

Install Kubernetes

Install kubectl


Take linux as an example

1. Download the first version

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

2. Give executable authority

chmod +x ./kubectl

3. Move to bin

sudo mv ./kubectl /usr/local/bin/kubectl

4. Check whether the installation is successful

kubectl version --client

Installing Minikube

For your convenience, kubernetes provides Minikube version, which can be installed locally


Install as directed on the official website:

1. Download the independent binary file and use:

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
  && chmod +x minikube

2. Add Minikube startup file to the path:

sudo mkdir -p /usr/local/bin/
sudo install minikube /usr/local/bin/

3. Check whether the installation is successful

Start Minikube

Use the minikub start command to start:

But there is a problem. The official website explains that if the virtual machine is not installed, you can use the docker driver to specify through -- driver=none:

Run with the minikube start -- VM driver = none command:

Prompt to install conntrack with root permission, and do as follows:

This run is successful. The first time you start it, you will download and install the related components:

If there is a network problem after downloading, use Alibaba's source:

minikube start --driver=none --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

Check the minikube installation status

dashboard on

Open with minikube dashboard

The following interface appears when accessing the url, indicating that minikube has been deployed successfully:

Basic terms

namespace:Kubernetes Use namespace to divide into multiple virtual clusters, which can be used by different teams or business groups to isolate resources, etc

Replication C ontroller:Pod , which is used to monitor the status of instances of the specified conditional pod and maintain the number of healthy copies of the instances to the specified number of copies. Its main functions include ensuring the number of pod instances, pod health, elastic scaling and rolling upgrade

Pod is the smallest scheduling unit of kubernetes, which can be regarded as the logical host of application services. It is generally understood that deploying several instances is to deploy several pods

Definition of replication controller:

  • Metadata: metadata is defined. name, namespace and label are defined here.
  • spec.replicas : used to define the number of copies required.
  • spec.template : used to define the template used to create a Pod when expanding.
  • resources.requests And limits: used to define the size and upper limit of the requested cpu and memory resources. Here, the cpu is 100m, which can be roughly understood as 0.1 cpu, and the memory is 256Mi, indicating 256M of memory.
  • env part: used to define environment variables when starting Docker instance. Here we define PROFILE and SERVER_PORT and JAVA_OPTS these environment variables.
  • ports section: defines the port name and port number in the container.

Service: provide external access to a group of pods that provide the same service, and have the service discovery and routing capabilities of a certain Pod

Label: used to associate a Pod with a Service. Each Pod can define a label, and then the Service can select which pods to serve through the label

D eployment:Replication Controller For the upgraded version of, the Deployment is displayed and controlled in more detail. For example, you can view the detailed progress and status of the upgrade, manage the version of each Deployment, facilitate rollback, and pause and continue the upgrade

To configure redis:

mkdir redis-k8s create a folder

Create a redis config file to store the redis startup configuration:

requirepass 123zxc

stop-writes-on-bgsave-error no
rdbcompression no
dbfilename dump.rdb

appendonly yes
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

dir /data/

Create redis-dp.yml To configure the deployment instance of redis:

apiVersion: apps/v1
kind: Deployment
  name: redis
    app: redis
  replicas: 1
      app: redis
        app: redis
      - name: redis
        image: redis 
        imagePullPolicy: IfNotPresent   
        - redis-server
        - "/redis-master/redis.conf"
            - containerPort: 6379
        - mountPath: ./redis-master-data
          name: data
        - mountPath: ./redis-master
          name: config
        - name: data
            path: /data
            type: DirectoryOrCreate
        - name: config
            name: example-redis-config
            - key: redis-config
              path: redis.conf

establish kustomization.yml File to configure Redis through data in ConfigMap

- name: example-redis-config
  - redis-config
  - redis-dp.yml

Run Deployment

Apply the entire kustomization folder to create ConfigMap and Deployment objects

kubectl apply -k .

View objects through kubectl get -k

In the example, the configuration volume is mounted under / redis master. It uses path to add the redis config key to the redis.conf In the file. Therefore, the file path of redis configuration is / redis master/ redis.conf .

To view information about ReplicaSet:

Several models of volumes


The containers in the Pod share the storage, and the Pod will be generated when it is created in the node. The life cycle of the Pod will follow the running Pod

            -  name:   xx
               emptyDir:  {}


Pod mounts the Node file system to the pod, and the life cycle follows the Node life cycle

	- name: html
        path: /data/pod/volume1
        type: DirectoryOrCreate


Pod life cycle configured with NFS, supports networked storage

  - name: nfs-storage
     path: "/data/disk1"


Kubemetes provides Secret to process sensitive data. The config in this example uses this:

Run service

You need to run a service to open the port in the deployment:

kubectl expose deployment redis --name=redis-service --port=6379

Get the service operation status through kubectl get services redis service:

Get the service details through kubectl describe services redis service:

It can be seen that the open ip address is, which can be accessed through python as follows:

The access is successful, and the simple stand-alone redis configuration is complete.

Dashboard view

Run minikube dashboard to open dasboard. You can view the details:

Delete Deployment, Service

yml file description

Source: https://www.cnblogs.com/wswang/p/10736766.html

# The full content of the pod definition file in yaml format:
apiVersion: v1       #Required, version number, e.g. v1
kind: Pod       #Required, Pod
metadata:       #Required, metadata
  name: string       #Required, Pod name
  namespace: string    #Required, namespace to which Pod belongs
  labels:      #Custom label
    - name: string     #Custom label name
  annotations:       #Custom comment list
    - name: string
spec:         #Required, detailed definition of container in Pod
  containers:      #Required, list of containers in Pod
  - name: string     #Required, container name
    image: string    #Required, image name of container
    imagePullPolicy: [Always | Never | IfNotPresent] #The policy of getting the image Alawys indicates downloading the image IfnotPresent indicates the priority of using the local image, otherwise downloading the image, and Nerver indicates only using the local image
    command: [string]    #List of startup commands for the container. If not specified, use the startup command used during packaging
    args: [string]     #List of start command parameters for the container
    workingDir: string     #Working directory of the container
    volumeMounts:    #Storage volume configuration mounted inside the container
    - name: string     #Refers to the name of the shared storage volume defined by the pod, which needs the volume name defined in the volumes [] section
      mountPath: string    #The absolute path of the storage volume mount in the container, which should be less than 512 characters
      readOnly: boolean    #Read only mode or not
    ports:       #List of port library numbers to be exposed
    - name: string     #Port number name
      containerPort: int   #Port number the container needs to listen to
      hostPort: int    #The port number that the host of the Container needs to listen to is the same as the Container by default
      protocol: string     #Port protocol, supports TCP and UDP, default TCP
    env:       #List of environment variables to be set before container running
    - name: string     #Environment variable name
      value: string    #Value of environment variable
    resources:       #Resource limits and request settings
      limits:      #Settings for resource restrictions
        cpu: string    #Cpu limit, in core, will be used for the docker run -- Cpu shares parameter
        memory: string     #Memory limit, the unit can be Mib/Gib, which will be used for the docker run --memory parameter
      requests:      #Settings for resource requests
        cpu: string    #Cpu request, initial available quantity of container start
        memory: string     #Clear memory, initial available quantity of container startup
    livenessProbe:     #For the health check settings of containers in Pod, when the probe fails to respond for several times, the container will be restarted automatically. The check methods include exec, httpGet and tcpSocket. Only one of them can be set for a container
      exec:      #Set the check mode in Pod container to exec mode
        command: [string]  #Command or script to be formulated for exec mode
      httpGet:       #To set HttpGet as the health check method for each container in Pod, you need to make Path and port
        path: string
        port: number
        host: string
        scheme: string
        - name: string
          value: string
      tcpSocket:     #Set the health check mode of each container in the Pod to tcpSocket mode
         port: number
       initialDelaySeconds: 0  #Time of first probe after container start, in seconds
       timeoutSeconds: 0   #Timeout of waiting response for container health check probe, in seconds, default 1 second
       periodSeconds: 0    #Set the regular detection time for container monitoring and inspection, in seconds, once every 10 seconds by default
       successThreshold: 0
       failureThreshold: 0
    restartPolicy: [Always | Never | OnFailure]#For the restart strategy of Pod, Always means that once the operation is terminated in any way, kubelet will restart. OnFailure means that only when Pod exits with a non-zero exit code, can it restart. Nerver means that the Pod will not restart again
    nodeSelector: obeject  #Setting NodeSelector means to schedule the Pod to the node containing the label, and specify it in the format of key: value
    imagePullSecrets:    #The secret name used in the Pull image, specified in the format of key: secret key
    - name: string
    hostNetwork:false      #Whether to use the host network mode is false by default. If it is set to true, it means to use the host network
    volumes:       #Define the list of shared storage volumes on this pod
    - name: string     #Shared storage volume names (there are many types of volumes)
      emptyDir: {}     #Storage volume of type emtyDir, a temporary directory in the same life cycle as Pod. Is null
      hostPath: string     #Storage volume of type hostPath, indicating the directory of the host where the Pod is mounted
        path: string     #The directory of the host where the Pod resides, which will be used for the mount directory in the same period
      secret:      #The storage volume of type secret mounts the cluster and the defined secret object into the container
        scretname: string  
        - key: string
          path: string
      configMap:     #The storage volume of type configMap mounts predefined configMap objects to the inside of the container
        name: string
        - key: string
          path: string

Tags: Redis Kubernetes Docker Linux

Posted on Fri, 12 Jun 2020 00:40:38 -0400 by ztkirby