Day 11 Knative 入门

Knative

实验环境
Ubuntu 20.04
Kubernetes v1.20(单节点)
Knative v0.20.0

安装 Docker

apt-get update
apt-get install -y apt-transport-https \
   ca-certificates \
   curl \
   gnupg-agent \
   software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
service docker start

安装 Kubernetes

(Knative 需要 Kubernetes v1.17 以上的版本)

apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

Docker 连接操作

cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
systemctl daemon-reload
systemctl restart docker
  • 关闭 Linux swap
swapoff -a
  • 建立丛集
kubeadm init  --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
  • 建立CNI
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  • 污染节点
kubectl taint nodes --all node-role.kubernetes.io/master-

部属 Knative

Knative 扩展了 Kubernetes,为开发人员提供了一套工具,可简化部署和管理可在任何地方运行的事件驱动应用程序的过程。

Knative有两个组件,可以独立安装或一起使用。

  • Serving 为基於无状态请求的从零到零的服务提供了一种抽象。
  • Eventing 提供了抽像以启用绑定事件源(例如Github Webhooks,Kafka)和使用者(例如Kubernetes或Knative Services)的绑定。

参考: https://knative.dev/docs/install/any-kubernetes-cluster/

Installing the Serving component

架构: https://knative.dev/docs/serving/

  • Install Serving CRD
kubectl apply --filename https://github.com/knative/serving/releases/download/v0.20.0/serving-crds.yaml
  • Install the core components of Serving
kubectl apply --filename https://github.com/knative/serving/releases/download/v0.20.0/serving-core.yaml

  • Install networking layer(Istio)

参考: https://knative.dev/docs/install/installing-istio/
部署需求: istioctl (v1.7 or later) installed.
目前官方建议部署istio v1.7

  • Installing Istio without sidecar injection

    • istio-minimal-operator.yaml
    cat << EOF > ./istio-minimal-operator.yaml
    apiVersion: install.istio.io/v1alpha1
    kind: IstioOperator
    spec:
      values:
        global:
          proxy:
            autoInject: disabled
          useMCP: false
          # The third-party-jwt is not enabled on all k8s.
          # See: https://istio.io/docs/ops/best-practices/security/#configure-third-party-service-account-tokens
          jwtPolicy: first-party-jwt
    
      addonComponents:
        pilot:
          enabled: true
    
      components:
        ingressGateways:
          - name: istio-ingressgateway
            enabled: true
    EOF
    
    istioctl install -f istio-minimal-operator.yaml
    
    • Install the Knative Istio controller
    kubectl apply --filename https://github.com/knative/net-istio/releases/download/v0.20.0/release.yaml
    
    • Fetch the External IP or CNAME
    kubectl --namespace istio-system get service istio-ingressgateway
    

  • Configure DNS

    • xip.io:提供一个default domain(k8s job),为Knative Serving配置预设的DNS後缀。

    注意:This will only work if the cluster LoadBalancer service exposes an IPv4 address or hostname, so it will not work with IPv6 clusters or local setups like Minikube. For these, see “Real DNS” or “Temporary DNS”.

    kubectl apply --filename https://github.com/knative/serving/releases/download/v0.20.0/serving-default-domain.yaml
    

最基本的Knative Serving部署完成。

Optional Serving extensions


<<:  【Day11】列举技术的实作 ─ 另外那篇

>>:  Day 11: 协作、团队与专案、学徒期 (待改进中... )

新新新手阅读 Angular 文件 - Add Service(2) - Day09

学习目标 这一篇是纪录阅读官方文件 Add services 的笔记内容。 本篇的内容是接续 Day...

Day 16:AWS是什麽?30天从动漫/影视作品看AWS服务应用 -《云端情人》part 3

Samantha和Theodore在一起的时候,时常提及自己在写钢琴曲,灵感来自於和Theodore...

[Day 23] - Django-REST-Framework Concrete View Classes 介绍

前言 上一篇中我们学习到了 GenericAPIView 以及 Mixins 的使用,让我们建立 R...

工程师要的是什麽?

「钱多事少离家近、睡觉睡到自然醒、位高权重责任轻;老板说话不用听、五年就领退休金、领钱领到手抽筋。」...

[Day20] 扩展你的设计:剖析回应可使用的元件并加以运用

现在,你应该有了一个能妥善处理各种意外情形。 且能妥善引导使用者满足他们主要需求的对话流了。 在今...