当前位置:网站首页>[5 minutes to play lighthouse] take you to the light kubernetes release k3s

[5 minutes to play lighthouse] take you to the light kubernetes release k3s

2022-06-24 06:34:00 lynnhou

1. Background Overview

As the most mainstream container orchestration platform at present ,Kubernetes As an infrastructure , Undertake and manage a large number of application services , Compared with the tradition based on VM Image deployment application , It has more 、 Perfect service arrangement and hosting capability . however , Only a few applications need to be deployed or only need to be developed 、 For users of the test environment , build 、 Complete configuration Kubernetes Clustering is a tedious and complicated process , It's easy for beginners to spend a lot of time 、 resources , And the income is limited . lately Lighthouse Launched K3s Apply image , It provides users with out of the box Kubernetes Environmental Science . As lightweight Kubernetes Distribution version ,K3s Passed CNCF Conformance certification , And highly optimized for multiple scenarios , Besides Lighthouse Also integrated in the application image Kubernetes-dashboard, It is convenient for users to cluster through the browser 、 Application management . This article introduces , How to use Lighthouse K3s Deploy 、 Manage your apps .

2. K3s brief introduction

K3s By Rancher Labs Released an open source 、 A very light weight Kubernetes Distribution version . stay Kubernetes On the basis of , Deleted some feature:

  • Legacy and non-default features
  • Alpha features
  • In-tree cloud providers
  • In-tree Storage
  • Docker (optional)

Non essential services are deleted at the functional level / function , These include kubernetes Some unstable and informal development version functions , Cut like this , It can not only reduce the probability of failure , It can also reduce the overall kubernetes Resource consumption of the management and control surface . All of the above 5 individual feature, Hence the name K3s. Besides , For application scenarios with limited resources ,K3s Added :

  • Simplified installation
  • SQLite3 support in addition to etcd
  • TLS management
  • Automatic Manifest and Helm Chart management
  • containerd、CoreDNS、Flannel

K3s It contains what we are familiar with kubernetes Components of , In order to be able to "Simplified installation”, K3S Integrate all components into one binary package (<100MB), In addition, it is installed by default Flannel As CNI plugin, Replace docker Use more lightweight 、 At the bottom containerd, And the use of SQLite3 Replace etcd As the storage of metadata .

Through the above cutting and optimization ,K3s Not only does it eliminate kubernetes The complexity of the installation process 、 Cumbersome steps , It provides users with out of the box deployment experience , It can also be used in the environment with limited resources , Can still provide users with a well functioning kubernetes colony , Keep up with kubernetes Consistent use experience .

3. Environmental preparation

3.1 Get ready Lighthouse Lightweight application servers

We started with Tencent cloud Lighthouse Lightweight app server purchase page , Buy a server . As shown in the figure below .

The specific configuration of the server is as follows :

  • regional : Hong Kong, China,
  • Mirror image : Apply image K3s
  • Example packages :CPU 1 nucleus Memory 2G SSD 50GB Peak bandwidth 6Mbps Monthly traffic 500GB
  • Instance name : Input K3s that will do .

Click on “ Buy now ”, After the payment, the server starts to create . When the server state is “ Running ” when , We can use it .

3.2 Firewall configuration

Default Kubernetes-dashboard Monitor in 9090 port , therefore , We need to open the firewall 9090 Port access . stay " Application management " page ,Lighthouse It also provides operation guidance for users :

Click on " determine “, thus , The user can access the access address shown in the figure Kubernetes-dashboard 了 .

3.3 Input dashboard token

Kubernetes-dashboard The login of requires the user to provide token, and token You need to log in to the server to get . Click on... As shown in the following figure “ Sign in ” Button , One click login to the server , Click replication " dashboard-token", Run in server , The output is the required login token, Copy and paste to the previous figure "Enter token" In the input box .

Click on Sign In Button , Login successful !

At this point, the user can use Kubernetes-dashboard Deploy and manage applications .

4. Deploy the application

The following will show how to K3s Upper Department wordpress, visit Kubernetes-dashboard, Click on the top right corner "+"

  1. Click on the figure below "+"

The following yaml Copy to edit box

apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
  selector:
    app: wordpress
    tier: frontend
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wp-pv-claim
  labels:
    app: wordpress
  annotations:
    volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
      - image: wordpress:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wp-pv-claim

---
apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels:
    app: wordpress
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        livenessProbe:
          tcpSocket:
            port: 3306
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim

---
apiVersion: v1
kind: Secret
metadata:
  name: mysql-pass
data:
  password: MWYyZDFlMmU2N2Rm

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: "traefik"
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: wordpress
          servicePort: 80

In this example :

  • We created mysql、wordpress Two Deployment, The corresponding Service,mysql The required password adopt secret Provide , Before deployment , Users can modify Secret Fill in the customized password.
  • Thanks to the K3s Provided by default local-path-provisioner, Users can create PVC( Default storageclass Has been designated as local-path),local-path-provisioner The corresponding PV. It is important to note that in PVC Of annotations You need to add volume.beta.kubernetes.io/storage-provisioner: rancher.io/local-path.
  • K3s The gateway is installed in the application image by default Traefik, It is convenient for users to expose services , For more detailed configuration, see traefik docs.

Click on Upload Start deployment , Wait for the deployment to complete

2. visit http://${ Instance public network IP}/ Get into wordpress Management interface

3. When we need to update the application , You can edit the corresponding... Directly on the panel Deployment

modify resources To configure , Click on "Update" Button ,Kubernetes Will update / upgrade Deployment, What needs to be added is

  • Kubernetes The upgrade strategy depends on Deployment designated strategy, Above Deployment designated strategy by recreate, therefore Kubernetes The old version will be closed first , Then start a new version , Users can specify according to their needs strategy, Details refer to Deployment update strategy.
  • To configure resources Guarantee limits == requests,Kubernetes The corresponding... Will be set Pod Of Qos Class by Guaranteed, So for key services , Especially when machine resources are scarce , Can guarantee its service quality , Details can be found in Qos Class.

The update is successful !

5. summary

This article shows Lighthouse K3s How to use the application image , And pass wordpress Application deployment example of , Shows how to use Kubernetes-dashboard Deploy 、 Management applications . If you want a quick and easy Kubernetes Environmental Science , For learning Kubernetes, Or to develop 、 test 、 Deploy the application ,Lighthouse application server (K3s Apply image ) Will be very suitable for you ! Give it a try !

原网站

版权声明
本文为[lynnhou]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/07/20210714175422383V.html

随机推荐