kubernetes Advanced articles

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/u011510825/article/details/83036908

    Before reading this article, you should understand some basic concepts kubernetes, such as: deployments, pods, services, etc., it is recommended to read The Basics .

 

There used docker students should have used docker-compose, with yaml file to write the configuration file. Here we are using to write the configuration file yaml, introduces several key parameters kubernetes, finally give the configuration and how to update the service instance.

apiVersion: apps/v1
# 版本
kind: Deployment
# kind中有Deployment、Service和Pod
metadata:
  name: application
# 元数据,主要用于定义名称和标签(label)
# 指定组成pod的实际对象,spec属性包括一些containers,storage,volumes,或者其他Kubernetes需要知道的参数,以及诸如是否在容器失败时重新启动容器的属性
spec:
  selector:
    matchLabels:
      app: application
  replicas: $REPLICAS
  # 副本数
  template:
    metadata:
      labels:
        app: application
    spec:
      containers:
      - image: registry-vpc.cn-hangzhou.aliyuncs.com/21epub/applicationstore:$TAG
        imagePullPolicy: Always
        name: applicationstore
        env:
        - name: DATE
          value: $DATE
        envFrom:
          - configMapRef:
              name: applicationstore
        livenessProbe:
          tcpSocket:
            port: 9090
          initialDelaySeconds: 15
          periodSeconds: 20          
      imagePullSecrets:
      - name: vpc-reg

We then depending on the configuration files, create deployments

kubectl create -f application.yaml

pod create fault location

Yaml finished file, if the container is not in the running state, you need to look at the contents of the file where YAML wrong, locate the problem.

kubectl describe pod application

Step by step debugging it.

After writing yaml file to start a container, yaml need to write the configuration file, because, you there may be multiple sets of environment, there are some parameters are different between each environment, such as test environment and production environment database must be used not the same, you need to write multiple sets configmap.

Such as this, this is a test environment

apiVersion: v1
kind: ConfigMap
metadata:
  name: application
  namespace: test
data:
  ZOO_SERVERS: zk-cs:2181
  DOCKER_ENV: test
  MYSQL_HOST: test.mysql.rds.aliyuncs.com

This is a production environment

apiVersion: v1
kind: ConfigMap
metadata:
  name: application
  namespace: www
data:
  ZOO_SERVERS: zk-cs:2181
  DOCKER_ENV: www
  MYSQL_HOST: www.mysql.rds.aliyuncs.com

 

After Well, these are ready, we should write a sh script, each finished building the mirror, automatically generated yaml file to start, and then apply the new yaml file, to the effect publishing applications.

This is an example:

#!/bin/sh
DATE=$(date)
export DATE

NAMESPACE=$1
export NAMESPACE

if [ $NAMESPACE = "test" ]
then
    REPLICAS=1
    REPLICAS_EPUB360=1
    REPLICAS_CELERY=1
    TAG="develop"
    EPUB360_CPU_REQUEST="0.5"
    EPUB360_MEM_REQUEST="0.5Gi"
    ZK_NUM=1
fi


if [ $NAMESPACE = "www" ]
then
    REPLICAS=2
    REPLICAS_EPUB360=3
    REPLICAS_CELERY=2
    TAG=$3
    EPUB360_CPU_REQUEST="1"
    EPUB360_MEM_REQUEST="1.1Gi"
    ZK_NUM=3
fi

export REPLICAS
export TAG

# applicationstore 
APPNAME=$2

kubectl apply -f $NAMESPACE/configmap/
envsubst < common/$APPNAME.yaml | kubectl apply --namespace=$NAMESPACE -f -

When invoked, passing the environment and service names (updated application test environment application)

sh /hooks/reload_app.sh test application
Sh This script can be used hubot robot to take us to implement, bearychat add this robot, then each will be able to automatically update the code in bearychat in. This is a brief introduction to do in my next chapter.

Guess you like

Origin blog.csdn.net/u011510825/article/details/83036908