<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Viet_1846 on Medium]]></title>
        <description><![CDATA[Stories by Viet_1846 on Medium]]></description>
        <link>https://medium.com/@viet1846?source=rss-dfeb01b4d84c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UoTpj-X7WEIa2QPFNEGiTQ.jpeg</url>
            <title>Stories by Viet_1846 on Medium</title>
            <link>https://medium.com/@viet1846?source=rss-dfeb01b4d84c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 01:19:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@viet1846/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 9][Real-time Components]: Apache Kafka, Kafka connect and Debezium]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-9-real-time-components-apache-kafka-kafka-connect-and-debezium-9f4a2e4606b4?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f4a2e4606b4</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[strimzi]]></category>
            <category><![CDATA[debezium-kafka-kubernetes]]></category>
            <category><![CDATA[debezium]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Thu, 08 Aug 2024 14:34:29 GMT</pubDate>
            <atom:updated>2024-08-23T18:28:09.716Z</atom:updated>
            <content:encoded><![CDATA[<p>These are well-known technologies, so I’ll provide a brief overview:</p><ul><li><strong>Apache Kafka</strong> is an open-source distributed event streaming platform used by thousands of organizations for high-performance data pipelines, streaming analytics, data integration, and critical applications.</li><li><strong>Kafka Connect</strong> specializes in streaming data to and from Kafka, simplifying the creation of high-quality, reliable, and efficient connector plugins. Kafka Connect also offers guarantees that are challenging to achieve with other frameworks.</li><li><strong>Debezium</strong> is an open-source distributed platform for capturing data changes. Once set up and connected to your databases, your applications can react to all inserts, updates, and deletes made to those databases. Debezium is robust and fast, ensuring your applications can respond promptly without missing any events, even in case of failures.</li></ul><p><em>The architecture is as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D6_daADn_XOnJoyrI03bdw.png" /><figcaption>Apache Kafka, Kafka connect and Debezium <em>architecture</em></figcaption></figure><p>In this article, I will use Strimzi to deploy a Kafka cluster and Kafka Connect on a Kubernetes environment. Strimzi provides a method to run an Apache Kafka cluster on Kubernetes or OpenShift in various deployment configurations.</p><h3>DEPLOYMENT STEPS</h3><p><strong>1. Initialize a Kubernetes cluster with Kind.</strong></p><p><strong>2. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino on Kubernetes</strong></p><p><strong>3. Install data sources:</strong></p><ul><li>Install MySQL on Kubernetes.</li><li>Install PostgreSQL on Kubernetes.</li></ul><p><strong>4. Install Kafka</strong></p><ul><li>Install Strimzi Operator</li><li>Create Kafka Cluster</li><li>Create Kafka topic</li></ul><p><strong>5. Test Produce message to user topic using Python</strong></p><p><strong>6. Install kafka connect</strong></p><ul><li>Build kafka connect image</li><li>Create kafka connect cluster</li></ul><p><strong>7. Config Amazon S3 Sink connector for user topic</strong></p><p><strong>8. Config Debezium MySQL connector &amp; Config Amazon S3 Sink connector for mysql topic</strong></p><p><strong>9. Config Debezium PostgreSQL connector &amp; Config Amazon S3 Sink connector for PostgreSQL topic</strong></p><p><strong>10. Destroy the Kind cluster</strong></p><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/kafka">https://github.com/viethqb/data-platform-notes/tree/main/kafka</a></p><h3>1. Initialize a Kubernetes cluster with Kind.</h3><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/kafka<br>&gt; kind create cluster --name dev --config deployment/kind/kind-config.yaml</pre><h4>2. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino on Kubernetes</h4><p><strong>Install Nginx Ingress Controller</strong></p><pre>&gt; helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>&gt; helm repo update<br>&gt; helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>&gt; kubectl -n ingress-nginx get po -owide</pre><p><strong>Install MinIO</strong></p><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f deployment/minio/minio-values.yaml bitnami/minio --create-namespace --debug --version 14.6.0<br>&gt; kubectl -n minio get po<br>&gt; kubectl get no -owide<br># NAME                STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION   CONTAINER-RUNTIME<br># dev-control-plane   Ready    control-plane   3m53s   v1.30.0   172.18.0.2    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker          Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.5    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker2         Ready    &lt;none&gt;          3m12s   v1.30.0   172.18.0.3    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker3         Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.4    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15</pre><pre># Add the following lines to the end of the /etc/hosts<br># 172.18.0.4  minio.lakehouse.local</pre><p><strong>Install Hive Metastore</strong></p><pre># hive-metastore-postgresql<br>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install metastore-db -n metastore -f deployment/hive/hive-metastore-postgres-values.yaml bitnami/postgresql --create-namespace --debug --version 15.4.2<br><br># Hive metastore<br># docker pull rtdl/hive-metastore:3.1.2<br># kind load docker-image rtdl/hive-metastore:3.1.2 --name dev<br>&gt; helm upgrade --install hive-metastore -n metastore -f deployment/hive/hive-metastore-values.yaml ../../charts/hive-metastore --create-namespace --debug</pre><p><strong>Install Trino</strong></p><pre>&gt; helm repo add trino https://trinodb.github.io/charts<br>&gt; helm upgrade --install trino -n trino -f deployment/trino/trino-values.yaml trino/trino --create-namespace --debug --version 0.21.0<br>&gt; kubectl -n trino get po</pre><h4>3. Install data sources</h4><p><strong>Install MySQL on Kubernetes</strong></p><pre>&gt; kubectl apply -f deployment/mysql/namespace.yaml <br>&gt; kubectl apply -f deployment/mysql/deployment.yaml <br>&gt; kubectl apply -f deployment/mysql/serrvice.yaml <br># user: root / password: debezium</pre><p><strong>Check mysql data</strong></p><pre>&gt; kubectl -n data-source exec -it deployments/mysql bash <br>bash-4.4# mysql -uroot -P3306 -hmysql.data-source -p <br>mysql&gt; show databases; <br>mysql&gt; show tables in inventory; <br>mysql&gt; select * from inventory.customers;</pre><p><strong>Install PostgreSQL on Kubernetes</strong></p><pre>&gt; kubectl apply -f deployment/postgres/postgres.yaml <br># user/password: data_engineer/password  <br>&gt; kubectl apply -f deployment/postgres/postgresql-client.yml <br>&gt; kubectl -n data-source exec -it postgresql-client sh <br>~ $ psql -h postgres.data-source -p 5432 -U data_engineer -d data_engineer <br>data_engineer=# \dt inventory.* <br>data_engineer=# select * from inventory.customers;</pre><h4>4. Install Kafka</h4><p><strong>Install Strimzi Operator</strong></p><pre>&gt; helm repo add strimzi https://strimzi.io/charts/<br>&gt; helm install kafka-operator strimzi/strimzi-kafka-operator --namespace=kafka --create-namespace --debug --version 0.41.0</pre><p>kafka-cluster.yaml</p><pre>apiVersion: kafka.strimzi.io/v1beta2<br>kind: Kafka<br>metadata:<br>  name: my-kafka-cluster<br>  namespace: kafka<br>spec:<br>  kafka:<br>    version: 3.7.0<br>    replicas: 3<br>    listeners:<br>      - name: plain<br>        port: 9092<br>        type: nodeport<br>        tls: false<br>        configuration:<br>          bootstrap:<br>            nodePort: 32100<br>      - name: tls<br>        port: 9093<br>        type: internal<br>        tls: true<br>    config:<br>      offsets.topic.replication.factor: 3<br>      transaction.state.log.replication.factor: 3<br>      transaction.state.log.min.isr: 2<br>      default.replication.factor: 3<br>      min.insync.replicas: 2<br>      inter.broker.protocol.version: &quot;3.7&quot;<br>    storage:<br>      type: jbod<br>      volumes:<br>        - id: 0<br>          type: persistent-claim<br>          size: 10Gi<br>          deleteClaim: false<br>  zookeeper:<br>    replicas: 3<br>    storage:<br>      type: persistent-claim<br>      size: 10Gi<br>      deleteClaim: false<br>  entityOperator:<br>    topicOperator: {}<br>    userOperator: {}</pre><p><strong>Create Kafka Cluster</strong></p><pre>&gt; kubectl apply -f deployment/kafka/kafka-cluster.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MNPTrfPNk8Lf3jfKhtnN2A.png" /></figure><p><strong>Create Kafka Topic</strong></p><p>Create topic for kafka connect</p><pre>&gt; kubectl apply -f deployment/kafka/connect-configs-topic.yaml <br>&gt; kubectl apply -f deployment/kafka/connect-offsets-topic.yaml <br>&gt; kubectl apply -f deployment/kafka/connect-status-topic.yaml</pre><p>List all topic</p><pre>&gt; kubectl -n kafka exec -it my-kafka-cluster-kafka-0 bash <br>[kafka@my-kafka-cluster-kafka-0 kafka]$ bin/kafka-topics.sh --list --bootstrap-server localhost:9092</pre><p>Using nodeport</p><pre>[kafka@my-kafka-cluster-kafka-0 kafka]$ bin/kafka-topics.sh --list --bootstrap-server 172.18.0.3:32100,172.18.0.4:32100,172.18.0.5:32100</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mbgMg4beoR0WZZCXltkhvQ.png" /></figure><h3>5. Produce message to user topic using Python</h3><p>src/producer.py</p><pre>from time import time<br>from kafka import KafkaProducer<br>from faker import Faker<br>import json, time<br>import os<br><br>BOOTSTRAP_SERVERS = os.getenv(<br>    &quot;BOOTSTRAP_SERVERS&quot;, &quot;172.25.0.2:32100,172.25.0.3:32100,172.25.0.4:32100&quot;<br>)<br>producer = KafkaProducer(bootstrap_servers=BOOTSTRAP_SERVERS)<br>faker = Faker()<br>def get_register():<br>    return {&quot;name&quot;: faker.name(), &quot;add&quot;: faker.year()}<br>def get_partitioner(key_bytes, all_partitions, available_partitions):<br>    return 0<br>def json_serializer(data):<br>    return json.dumps(data).encode(&quot;utf-8&quot;)<br>producer = KafkaProducer(<br>    bootstrap_servers=BOOTSTRAP_SERVERS,  # server name<br>    value_serializer=json_serializer,  # function callable<br>    # partitioner = get_partitioner, # function return 0 &gt;&gt;&gt; only partition_0 can received messages<br>)<br>while 1 == 1:<br>    user = get_register()<br>    # print(user)<br>    producer.send(&quot;users&quot;, user)<br>    time.sleep(1)</pre><pre># Python 3.10.14<br>&gt; python3.10 -m venv .venv<br>&gt; source .venv/bin/activate<br>&gt; pip install -r src/requirements.txt<br>&gt; export BOOTSTRAP_SERVERS=&quot;172.18.0.3:32100,172.18.0.4:32100,172.18.0.5:32100&quot;<br>&gt; python3 src/producer.py<br><br>&gt; kubectl -n kafka exec -it my-kafka-cluster-kafka-0 bash<br>&gt; bin/kafka-console-consumer.sh --topic users --from-beginning --bootstrap-server 172.18.0.3:32100,172.18.0.4:32100,172.18.0.5:32100</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZA-wWVB7XEEMC7Myvh6P2w.png" /></figure><h4>6. Install kafka connect</h4><p><strong>Dockerfile</strong></p><pre>FROM confluentinc/cp-kafka-connect:7.6.1 as cp<br>RUN confluent-hub install --no-prompt confluentinc/kafka-connect-s3:10.5.12<br>RUN confluent-hub install --no-prompt confluentinc/kafka-connect-avro-converter:7.6.1<br>RUN confluent-hub install --no-prompt tabular/iceberg-kafka-connect:0.6.18<br>RUN confluent-hub install --no-prompt debezium/debezium-connector-mysql:2.4.2<br>RUN confluent-hub install --no-prompt debezium/debezium-connector-postgresql:2.5.4<br>RUN confluent-hub install --no-prompt debezium/debezium-connector-sqlserver:2.5.4<br>RUN confluent-hub install --no-prompt debezium/debezium-connector-mongodb:2.4.2<br>FROM quay.io/strimzi/kafka:0.41.0-kafka-3.7.0<br>USER root:root<br># Add S3 dependency<br>COPY --from=cp /usr/share/confluent-hub-components/confluentinc-kafka-connect-s3/ /opt/kafka/plugins/kafka-connect-s3/<br># Add Avro Converter dependency<br>COPY --from=cp /usr/share/confluent-hub-components/confluentinc-kafka-connect-avro-converter/ /opt/kafka/plugins/confluentinc-kafka-connect-avro-converter/<br># Add Iceberg dependency<br>COPY --from=cp /usr/share/confluent-hub-components/tabular-iceberg-kafka-connect/ /opt/kafka/plugins/tabular-iceberg-kafka-connect/<br># Add debezium-connector-mysql <br>COPY --from=cp /usr/share/confluent-hub-components/debezium-debezium-connector-mysql/ /opt/kafka/plugins/debezium-debezium-connector-mysql/<br># Add debezium-connector-postgresql <br>COPY --from=cp /usr/share/confluent-hub-components/debezium-debezium-connector-postgresql/ /opt/kafka/plugins/debezium-debezium-connector-postgresql/<br># Add debezium-connector-sqlserver <br>COPY --from=cp /usr/share/confluent-hub-components/debezium-debezium-connector-sqlserver/ /opt/kafka/plugins/debezium-debezium-connector-sqlserver/<br># Add debezium-connector-mongodb <br>COPY --from=cp /usr/share/confluent-hub-components/debezium-debezium-connector-mongodb/ /opt/kafka/plugins/debezium-debezium-connector-mongodb/</pre><p><strong>Build kafka connect image</strong></p><pre># Replace viet1846 by your repository<br>&gt; docker build -t viet1846/kafka-connect:0.41.0 -f deployment/kafka/Dockerfile deployment/kafka <br>&gt; docker push viet1846/kafka-connect:0.41.0</pre><p><strong>connect.yaml</strong></p><pre>apiVersion: kafka.strimzi.io/v1beta2<br>kind: KafkaConnect<br>metadata:<br>  name: connect-cluster<br>  namespace: kafka<br>  annotations:<br>    strimzi.io/use-connector-resources: &quot;true&quot;<br>spec:<br>  image: viet1846/kafka-connect:0.41.0<br>  version: 3.7.0<br>  replicas: 3<br>  bootstrapServers: my-kafka-cluster-kafka-plain-bootstrap:9092<br>  # tls:<br>  #   trustedCertificates:<br>  #     - secretName: my-kafka-cluster-cluster-ca-cert<br>  #       certificate: ca.crt<br>  config:<br>    bootstrap.servers: my-kafka-cluster-kafka-plain-bootstrap:9092<br>    group.id: connect-cluster<br>    key.converter: org.apache.kafka.connect.json.JsonConverter<br>    value.converter: org.apache.kafka.connect.json.JsonConverter<br>    internal.key.converter: org.apache.kafka.connect.json.JsonConverter<br>    internal.value.converter: org.apache.kafka.connect.json.JsonConverter<br>    key.converter.schemas.enable: false<br>    value.converter.schemas.enable: false<br>    offset.storage.topic: connect-offsets<br>    offset.storage.replication.factor: 1<br>    config.storage.topic: connect-configs<br>    config.storage.replication.factor: 1<br>    status.storage.topic: connect-status<br>    status.storage.replication.factor: 1<br>    offset.flush.interval.ms: 10000<br>    plugin.path: /opt/kafka/plugins<br>    offset.storage.file.filename: /tmp/connect.offsets<br>  template:<br>    connectContainer:<br>      env:<br>        - name: AWS_ACCESS_KEY_ID<br>          value: &quot;admin&quot;<br>        - name: AWS_SECRET_ACCESS_KEY<br>          value: &quot;password&quot;</pre><p><strong>Create kafka connect cluster</strong></p><pre>kubectl apply -f deployment/kafka/connect.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9AB89qzkgviuYQHXwSETCw.png" /></figure><h3>7. Config Amazon S3 Sink connector for user topic</h3><pre>kubectl apply -f deployment/kafka/sink-user-topic-to-s3-connector.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Fr-eCeMA9XD0EnQmnh4ww.png" /></figure><p>Produce message to users topic using Python</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQlVH9vlYG5d8ysjHmU2TQ.png" /></figure><p>Check Minio file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1WkaTrHofFiTXdhoDUfrw.png" /></figure><p>Trino</p><pre>trino&gt; CREATE SCHEMA lakehouse.raw WITH (location = &#39;s3a://lakehouse/raw.db/&#39;);<br>trino&gt; CREATE TABLE IF NOT EXISTS minio.raw.python_users(<br>	json_string             varchar,<br>    year                    varchar,<br>    month                   varchar,<br>    day                     varchar,<br>    hour                    varchar<br>)WITH<br>(<br> 	format = &#39;TEXTFILE&#39;,<br> 	partitioned_by = ARRAY[ &#39;year&#39;, &#39;month&#39;, &#39;day&#39;, &#39;hour&#39; ],<br> 	external_location = &#39;s3a://kafka/topics/users&#39;<br>);<br>trino&gt; CALL minio.system.sync_partition_metadata(&#39;raw&#39;, &#39;mysql_customers&#39;, &#39;FULL&#39;);<br>trino&gt; select <br>         cast(json_extract(json_string, &#39;$.add&#39;) as int) as add, <br>         cast(json_extract(json_string, &#39;$.name&#39;) as varchar) as name, <br>         cast(json_extract(json_string, &#39;$.message_ts&#39;) as varchar) as message_ts <br>       from minio.raw.python_users <br>       limit 5;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bVL5zhNXakegHgLxLAZo9A.png" /></figure><h3>8. Config Debezium MySQL connector &amp; Config Amazon S3 Sink connector for mysql topic</h3><p><strong>debezium-connector-mysql.yaml</strong></p><pre>apiVersion: kafka.strimzi.io/v1beta2<br>kind: KafkaConnector<br>metadata:<br>  name: debezium-connector-mysql<br>  namespace: kafka<br>  labels:<br>    strimzi.io/cluster: connect-cluster<br>spec:<br>  class: io.debezium.connector.mysql.MySqlConnector<br>  tasksMax: 1<br>  config:<br>    tasks.max: 1<br>    database.hostname: mysql.data-source<br>    database.port: 3306<br>    database.user: root<br>    database.password: debezium<br>    database.server.id: 184054<br>    topic.prefix: mysql<br>    database.include.list: inventory<br>    schema.history.internal.kafka.bootstrap.servers: my-kafka-cluster-kafka-plain-bootstrap:9092<br>    schema.history.internal.kafka.topic: schema-changes.inventory</pre><p><strong>Config Mysql CDC source connector</strong></p><pre>kubectl apply -f deployment/kafka/debezium-connector-mysql.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-M1PGW6vnrW-_qhLN-9GQ.png" /></figure><p><strong>Update Mysql</strong></p><pre>&gt; kubectl -n data-source exec -it deployments/mysql bash<br>bash-4.4# mysql -uroot -P3306 -hmysql.data-source -p<br>mysql&gt; update inventory.customers set first_name=&#39;Sally updated&#39; where id=1001;<br>mysql&gt; insert into inventory.customers values (1005, &#39;Viet&#39;, &#39;Hoang&#39;, &#39;viet.hoang@abc.com&#39;);<br>mysql&gt; delete from inventory.customers where id=1005;</pre><p>Check kafka topic</p><pre>&gt; kubectl -n kafka exec -it my-kafka-cluster-kafka-0 bash<br>[kafka@my-kafka-cluster-kafka-0 kafka]$ bin/kafka-topics.sh --list --bootstrap-server localhost:9092<br>[kafka@my-kafka-cluster-kafka-0 kafka]$ bin/kafka-console-consumer.sh --topic mysql.inventory.customers --from-beginning --bootstrap-server 172.18.0.3:32100,172.18.0.4:32100,172.18.0.5:32100</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lj6CrEgemxdOGl29BgKZvQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LkWjV9TmpxBr3a6fHjmMcA.png" /></figure><p><strong>sink-mysql-kafka-topic-to-s3-connector.yaml</strong></p><pre>apiVersion: kafka.strimzi.io/v1beta2<br>kind: KafkaConnector<br>metadata:<br>  name: &quot;sink-mysql-kafka-topic-to-s3-connector&quot;<br>  namespace: &quot;kafka&quot;<br>  labels:<br>    strimzi.io/cluster: connect-cluster<br>spec:<br>  class: io.confluent.connect.s3.S3SinkConnector<br>  config:<br>    connector.class: io.confluent.connect.s3.S3SinkConnector<br>    task.max: &quot;1&quot;<br>    topics: mysql.inventory.addresses, mysql.inventory.customers, mysql.inventory.geom, mysql.inventory.orders, mysql.inventory.products, mysql.inventory.products_on_hand<br>    s3.region: us-east-1<br>    s3.bucket.name: kafka<br>    s3.part.size: &quot;5242880&quot;<br>    flush.size: 1<br>    store.url: &lt;http://minio.minio.svc.cluster.local:9000&gt;<br>    storage.class: io.confluent.connect.s3.storage.S3Storage<br>    format.class: io.confluent.connect.s3.format.json.JsonFormat<br>    schema.generator.class: &quot;io.confluent.connect.storage.hive.schema.DefaultSchemaGenerator&quot;<br>    partitioner.class: io.confluent.connect.storage.partitioner.TimeBasedPartitioner<br>    transforms: &quot;insertTS,formatTS&quot;<br>    transforms.insertTS.type: &quot;org.apache.kafka.connect.transforms.InsertField$Value&quot;<br>    transforms.insertTS.timestamp.field: &quot;message_ts&quot;<br>    transforms.formatTS.type: &quot;org.apache.kafka.connect.transforms.TimestampConverter$Value&quot;<br>    transforms.formatTS.format: &quot;yyyy-MM-dd HH:mm:ss:SSS&quot;<br>    transforms.formatTS.field: &quot;message_ts&quot;<br>    transforms.formatTS.target.type: &quot;string&quot;<br>    behavior.on.null.values: ignore<br>    partition.duration.ms: 60000<br>    path.format: &quot;&#39;year&#39;=YYYY/&#39;month&#39;=MM/&#39;day&#39;=dd/&#39;hour&#39;=HH&quot;<br>    locale: &quot;vi-VN&quot;<br>    timezone: &quot;Asia/Ho_Chi_Minh&quot;</pre><p><strong>Config Amazon S3 Sink connector for mysql topic</strong></p><pre>kubectl apply -f deployment/kafka/sink-mysql-kafka-topic-to-s3-connector.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFSzcIpNbZJfS_chKpwHrQ.png" /></figure><p><strong>Check MinIO</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvJYG-R40_MjQiMby8Ah1A.png" /></figure><h3>9. Config Debezium PostgreSQL connector &amp; Config Amazon S3 Sink connector for PostgreSQL topic</h3><p><strong>debezium-connector-postgres.yaml</strong></p><pre>apiVersion: kafka.strimzi.io/v1beta2<br>kind: KafkaConnector<br>metadata:<br>  name: debezium-connector-postgres<br>  namespace: kafka<br>  labels:<br>    strimzi.io/cluster: connect-cluster<br>spec:<br>  class: io.debezium.connector.postgresql.PostgresConnector<br>  tasksMax: 1<br>  config:<br>    tasks.max: 1<br>    plugin.name: pgoutput<br>    database.hostname: postgres.data-source<br>    database.port: 5432<br>    database.user: &quot;data_engineer&quot;<br>    database.password: &quot;password&quot;<br>    database.dbname: &quot;data_engineer&quot;<br>    database.server.id: 184055<br>    topic.prefix: postgres<br>    schema.include.list: inventory<br>    schema.history.internal.kafka.bootstrap.servers: my-kafka-cluster-kafka-plain-bootstrap:9092<br>    schema.history.internal.kafka.topic: schema-changes.inventory</pre><p><strong>Config Debezium PostgreSQL connector</strong></p><pre>kubectl apply -f deployment/kafka/debezium-connector-postgres.yaml</pre><p><strong>Config Amazon S3 Sink connector for PostgreSQL topic</strong></p><pre>kubectl apply -f deployment/kafka/sink-postgres-kafka-topic-to-s3-connector.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1251_gzc6B1jsaGxOc4Cw.png" /></figure><p><strong>Update Postgres</strong></p><pre>k -n kafka exec -it postgresql-client sh<br>data_engineer=# \\dt inventory.*<br>#                   List of relations<br>#   Schema   |       Name       | Type  |     Owner     <br># -----------+------------------+-------+---------------<br>#  inventory | customers        | table | data_engineer<br>#  inventory | geom             | table | data_engineer<br>#  inventory | orders           | table | data_engineer<br>#  inventory | products         | table | data_engineer<br>#  inventory | products_on_hand | table | data_engineer<br>#  inventory | spatial_ref_sys  | table | data_engineer<br># (6 rows)<br>update inventory.customers set first_name=&#39;Sally Marie&#39; where id=1001;</pre><p><strong>Check Kafka topic</strong></p><pre>kubectl -n kafka exec -it my-kafka-cluster-kafka-0 bash<br>[kafka@my-kafka-cluster-kafka-0 kafka]$ bin/kafka-topics.sh --list --bootstrap-server localhost:9092<br>[kafka@my-kafka-cluster-kafka-0 kafka]$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic postgres.inventory.customers --from-beginning</pre><p><strong>Check MinIO</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3sIF5t-aoZ_FLv96QamaQ.png" /></figure><h3>10. Destroy the Kind cluster</h3><pre>kind delete cluster -n dev</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f4a2e4606b4" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-9-real-time-components-apache-kafka-kafka-connect-and-debezium-9f4a2e4606b4">[Kubernetes Data Platform][Part 9][Real-time Components]: Apache Kafka, Kafka connect and Debezium</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 8][Main Components]: Data warehouse with StarRocks]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-8-main-components-data-warehouse-with-starrocks-c845f2dc69d3?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c845f2dc69d3</guid>
            <category><![CDATA[data-lakehouse]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[starrocks]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Thu, 08 Aug 2024 00:14:36 GMT</pubDate>
            <atom:updated>2024-08-23T18:28:14.111Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>StarRocks</strong> is a high-performance, massively parallel processing (MPP) SQL data warehouse optimized for big data analytics. Built on a significantly enhanced version of <strong><em>Apache Doris</em></strong>, it delivers exceptional speed, reliability, and ease of use.</p><h3><strong>StarRocks Architecture</strong></h3><p>StarRocks supports two main architectures: Shared-nothing and Shared-data. Each architecture has its own characteristics and is suitable for different use cases.</p><h4><strong>Shared-data Clusters</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cn9pe8xnd41rcNc3i0WV_g.png" /><figcaption>StarRocks Shared-data Architecture</figcaption></figure><p><strong>Architecture:</strong> In this model, data is stored on a shared storage system (such as S3, Google Cloud Storage, Azure Blob Storage, MinIO), while compute nodes are only responsible for processing queries and computations.</p><p><strong>Advantages:</strong></p><ul><li>Lower cost by leveraging the advantages of cheap object storage.</li><li>Independent scalability between compute and storage.</li><li>Better data recovery capabilities.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>Performance may be lower than shared-nothing in some cases.</li><li>Dependent on the performance of the storage system.</li></ul><h4><strong>Shared-nothing Clusters</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUa34duikOPxMrETOzjw3Q.png" /><figcaption>StarRocks Shared-nothing Architecture</figcaption></figure><p><strong>Architecture:</strong> In this model, each node in the cluster is independent and does not share any resources with other nodes. Each node has its own memory, CPU, and hard drive, and is responsible for storing, computing, and managing its own data.</p><p><strong>Advantages:</strong></p><ul><li>Flexible scalability: Nodes can be easily added or removed to meet changing needs.</li><li>High fault tolerance: A failure on one node does not affect other nodes.</li><li>Good performance for heavy OLAP workloads.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>Higher cost due to the requirement for more hardware resources.</li><li>More complex management.</li></ul><h4>DEPLOYMENT STEPS</h4><ol><li>Initialize a Kubernetes cluster with Kind.</li><li>Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino, Apache Airflow on Kubernetes</li><li>Trigger DAG: dbt_jaffle-shop-classic_example</li><li>Install StarRocks: I will deploy using the Shared-data cluster architecture.</li><li>Config and Query Iceberg catalog</li><li>Destroy the Kind cluster</li></ol><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/starrocks">https://github.com/viethqb/data-platform-notes/tree/main/starrocks</a></p><h4>1. Initialize a Kubernetes cluster with Kind.</h4><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/doris<br>&gt; kind create cluster --name dev --config deployment/kind/kind-config.yaml</pre><h4>2. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino on Kubernetes</h4><p><strong>Install Nginx Ingress Controller</strong></p><pre>&gt; helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>&gt; helm repo update<br>&gt; helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>&gt; kubectl -n ingress-nginx get po -owide</pre><p><strong>Install MinIO</strong></p><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f deployment/minio/minio-values.yaml bitnami/minio --create-namespace --debug --version 14.6.0<br>&gt; kubectl -n minio get po<br>&gt; kubectl get no -owide<br># NAME                STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION   CONTAINER-RUNTIME<br># dev-control-plane   Ready    control-plane   3m53s   v1.30.0   172.18.0.2    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker          Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.5    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker2         Ready    &lt;none&gt;          3m12s   v1.30.0   172.18.0.3    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker3         Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.4    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15</pre><pre># Add the following lines to the end of the /etc/hosts<br>172.18.0.4  minio.lakehouse.local  airflow.lakehouse.local</pre><p><strong>Install Hive Metastore</strong></p><pre># hive-metastore-postgresql<br>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install metastore-db -n metastore -f deployment/hive/hive-metastore-postgres-values.yaml bitnami/postgresql --create-namespace --debug --version 15.4.2</pre><pre># Hive metastore<br># docker pull rtdl/hive-metastore:3.1.2<br># kind load docker-image rtdl/hive-metastore:3.1.2 --name dev<br>&gt; helm upgrade --install hive-metastore -n metastore -f deployment/hive/hive-metastore-values.yaml ../../charts/hive-metastore --create-namespace --debug</pre><p><strong>Install Trino</strong></p><pre>&gt; helm repo add trino https://trinodb.github.io/charts<br>&gt; helm upgrade --install trino -n trino -f deployment/trino/trino-values.yaml trino/trino --create-namespace --debug --version 0.21.0<br>&gt; kubectl -n trino get po</pre><p><strong>Install Apache Airflow</strong></p><pre>&gt; helm repo add airflow https://airflow.apache.org/<br>&gt; helm repo update<br>&gt; helm upgrade --install airflow airflow/airflow -f deployment/airflow/airflow-values.yaml --namespace airflow --create-namespace --debug --version 1.13.1 --timeout 600s<br>&gt; kubectl -n airflow get po</pre><p>Access at <a href="http://airflow.lakehouse.local/connection/list/">http://airflow.lakehouse.local/connection/list/</a> ⇒ user: admin &amp; password: admin</p><p><strong>Config S3 Connection and Kubernetes Connection in Airflow UI</strong></p><p>Access Airflow Connection at <a href="http://airflow.lakehouse.local/connection/list/">http://airflow.lakehouse.local/connection/list/</a> ⇒ add new record</p><pre>Connection Id: s3_default<br>Connection Type: Amazon Web Services<br>AWS Access Key ID: admin <br>AWS Secret Access Key: password<br>Extra: {&quot;endpoint_url&quot;: &quot;&lt;http://minio.minio.svc.cluster.local:9000&gt;&quot;}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PVAebL5bZs-fYnEh8Y62w.png" /></figure><pre>Connection Id: kubernetes_default<br>Connection Type: Kubernetes Cluster Connection<br>In cluster configuration: yes<br>Disable SSL: yes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmaPb9Sg_H26JJ9dSvBbkg.png" /></figure><h4>3. Trigger DAG: dbt_jaffle-shop-classic_example</h4><p>Create jaffle_shop schema:</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; CREATE SCHEMA lakehouse.jaffle_shop WITH (location = &#39;s3a://lakehouse/jaffle_shop.db/&#39;);</pre><p>Access at <a href="http://airflow.lakehouse.local/dags/dbt_jaffle-shop-classic_example/grid">http://airflow.lakehouse.local/dags/dbt_jaffle-shop-classic_example/grid</a> ⇒ Trigger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kuhx7_aNXoh2ih7_gqaR9A.png" /></figure><p>Check tables from jaffle_shop schema:</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; show tables from lakehouse.jaffle_shop;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAwa6BOvOkjJmDlVzXiXGA.png" /></figure><h3>4. Install Install StarRocks</h3><p>Docs: <a href="https://github.com/StarRocks/starrocks-kubernetes-operator/tree/main/doc">https://github.com/StarRocks/starrocks-kubernetes-operator/tree/main/doc</a></p><p><strong>Install starrocks-kubernetes-operator ⇒ Custom resource: starrocksclusters.starrocks.com</strong></p><pre>kubectl apply -f https://raw.githubusercontent.com/StarRocks/starrocks-kubernetes-operator/main/deploy/starrocks.com_starrocksclusters.yaml<br>kubectl apply -f https://raw.githubusercontent.com/StarRocks/starrocks-kubernetes-operator/main/deploy/operator.yaml</pre><p><strong>Create Starrocks cluster with root password is empty</strong></p><p><strong>shared_data_mode.yaml</strong></p><pre>apiVersion: starrocks.com/v1<br>kind: StarRocksCluster<br>metadata:<br>  name: starrockscluster<br>  namespace: starrocks<br>spec:<br>  starRocksFeSpec:<br>    image: starrocks/fe-ubuntu:3.3-latest<br>    replicas: 3<br>    # limits:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # requests:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # feEnvVars:<br>    #   - name: &quot;MYSQL_PWD&quot;<br>    #     valueFrom:<br>    #       secretKeyRef:<br>    #         name: rootcredential<br>    #         key: password<br>    service:<br>      type: NodePort # export fe service<br>      ports:<br>        - name: query # fill the name from the fe service ports<br>          nodePort: 32755<br>          port: 9030<br>          containerPort: 9030<br>    storageVolumes:<br>      - name: fe-storage-meta<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 10Gi # the size of storage volume for metadata<br>        mountPath: /opt/starrocks/fe/meta # the path of metadata<br>      - name: fe-storage-log<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 1Gi # the size of storage volume for log<br>        mountPath: /opt/starrocks/fe/log # the path of log<br>    configMapInfo:<br>      configMapName: starrockscluster-fe-cm<br>      resolveKey: fe.conf<br>  starRocksCnSpec:<br>    image: starrocks/cn-ubuntu:3.3-latest<br>    replicas: 1<br>    # limits:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # requests:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # cnEnvVars:<br>    #   - name: &quot;MYSQL_PWD&quot;<br>    #     valueFrom:<br>    #       secretKeyRef:<br>    #         name: rootcredential<br>    #         key: password<br>    configMapInfo:<br>      configMapName: starrockscluster-cn-cm<br>      resolveKey: cn.conf<br>    storageVolumes:<br>      - name: cn-storage-data<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 10Gi # the size of storage volume for data<br>        mountPath: /opt/starrocks/cn/storage # the path of data<br>      - name: cn-storage-log<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 1Gi # the size of storage volume for log<br>        mountPath: /opt/starrocks/cn/log # the path of log<br>  starRocksFeProxySpec:<br>    replicas: 1<br>    # limits:<br>    #   cpu: 1<br>    #   memory: 2Gi<br>    # requests:<br>    #   cpu: 1<br>    #   memory: 2Gi<br>    service:<br>      type: NodePort # export fe proxy service<br>      ports:<br>        - name: http-port # fill the name from the fe proxy service ports<br>          containerPort: 8080<br>          nodePort: 30180 # The range of valid ports is 30000-32767<br>          port: 8080<br><br>    resolver: &quot;kube-dns.kube-system.svc.cluster.local&quot; # this is the default dns server.<br><br>---<br># fe config<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: starrockscluster-fe-cm<br>  namespace: starrocks<br>  labels:<br>    cluster: starrockscluster<br>data:<br>  fe.conf: |<br>    LOG_DIR = ${STARROCKS_HOME}/log<br>    DATE = &quot;$(date +%Y%m%d-%H%M%S)&quot;<br>    JAVA_OPTS=&quot;-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:+UseMembar -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=7 -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -XX:-CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -Xloggc:${LOG_DIR}/fe.gc.log.$DATE&quot;<br>    JAVA_OPTS_FOR_JDK_9=&quot;-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=7 -XX:+CMSClassUnloadingEnabled -XX:-CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -Xlog:gc*:${LOG_DIR}/fe.gc.log.$DATE:time&quot;<br>    JAVA_OPTS_FOR_JDK_11=&quot;-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:+UseG1GC -Xlog:gc*:${LOG_DIR}/fe.gc.log.$DATE:time&quot;<br>    http_port = 8030<br>    rpc_port = 9020<br>    query_port = 9030<br>    edit_log_port = 9010<br>    mysql_service_nio_enabled = true<br>    sys_log_level = INFO<br>    run_mode = shared_data<br>    cloud_native_meta_port = 6090<br>    # 是否允许 StarRocks 使用 FE 配置文件中指定的存储相关属性创建默认存储卷<br>    enable_load_volume_from_conf = true<br>    aws_s3_path = starrocks<br>    aws_s3_region = us-east-1<br>    aws_s3_endpoint = http://minio.minio.svc.cluster.local:9000<br>    aws_s3_access_key = admin<br>    aws_s3_secret_key = password<br><br>---<br># cn config<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: starrockscluster-cn-cm<br>  namespace: starrocks<br>  labels:<br>    cluster: starrockscluster<br>data:<br>  cn.conf: |<br>    sys_log_level = INFO<br>    # ports for admin, web, heartbeat service<br>    thrift_port = 9060<br>    webserver_port = 8040<br>    heartbeat_service_port = 9050<br>    brpc_port = 8060</pre><p><strong>Create Starrocks cluster with root password is empty</strong></p><pre>&gt; kubectl create secret generic rootcredential --from-literal=password=mysql_password<br>&gt; kubectl apply -f deployment/starrocks/shared_data_mode.yaml<br>&gt; kubectl -n starrocks get po -owide<br>&gt; kubectl -n starrocks get starrocksclusters.starrocks.com</pre><p><strong>Change Starrocks password:</strong></p><pre># Connect to nodeport<br>&gt; mysql --host=172.18.0.4 --port=32755 --user=root<br>MySQL [(none)]&gt; SET PASSWORD FOR &#39;root&#39; = PASSWORD(&#39;mysql_password&#39;);<br>MySQL [(none)]&gt; quit</pre><p><strong>shared_data_mode_with_root_password.yaml</strong></p><pre>apiVersion: starrocks.com/v1<br>kind: StarRocksCluster<br>metadata:<br>  name: starrockscluster<br>  namespace: starrocks<br>spec:<br>  starRocksFeSpec:<br>    image: starrocks/fe-ubuntu:3.3-latest<br>    replicas: 3<br>    # limits:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # requests:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    feEnvVars:<br>      - name: &quot;MYSQL_PWD&quot;<br>        valueFrom:<br>          secretKeyRef:<br>            name: rootcredential<br>            key: password<br>    service:<br>      type: NodePort # export fe service<br>      ports:<br>        - name: query # fill the name from the fe service ports<br>          nodePort: 32755<br>          port: 9030<br>          containerPort: 9030<br>    storageVolumes:<br>      - name: fe-storage-meta<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 10Gi # the size of storage volume for metadata<br>        mountPath: /opt/starrocks/fe/meta # the path of metadata<br>      - name: fe-storage-log<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 1Gi # the size of storage volume for log<br>        mountPath: /opt/starrocks/fe/log # the path of log<br>    configMapInfo:<br>      configMapName: starrockscluster-fe-cm<br>      resolveKey: fe.conf<br>  starRocksCnSpec:<br>    image: starrocks/cn-ubuntu:3.3-latest<br>    replicas: 1<br>    # limits:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # requests:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    cnEnvVars:<br>      - name: &quot;MYSQL_PWD&quot;<br>        valueFrom:<br>          secretKeyRef:<br>            name: rootcredential<br>            key: password<br>    configMapInfo:<br>      configMapName: starrockscluster-cn-cm<br>      resolveKey: cn.conf<br>    storageVolumes:<br>      - name: cn-storage-data<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 10Gi # the size of storage volume for data<br>        mountPath: /opt/starrocks/cn/storage # the path of data<br>      - name: cn-storage-log<br>        # storageClassName: &quot;nfs-client&quot; # you can remove this line if you want to use the default storage class<br>        storageSize: 1Gi # the size of storage volume for log<br>        mountPath: /opt/starrocks/cn/log # the path of log<br>  starRocksFeProxySpec:<br>    replicas: 1<br>    # limits:<br>    #   cpu: 1<br>    #   memory: 2Gi<br>    # requests:<br>    #   cpu: 1<br>    #   memory: 2Gi<br>    service:<br>      type: NodePort # export fe proxy service<br>      ports:<br>        - name: http-port # fill the name from the fe proxy service ports<br>          containerPort: 8080<br>          nodePort: 30180 # The range of valid ports is 30000-32767<br>          port: 8080<br><br>    resolver: &quot;kube-dns.kube-system.svc.cluster.local&quot; # this is the default dns server.<br><br>---<br># fe config<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: starrockscluster-fe-cm<br>  namespace: starrocks<br>  labels:<br>    cluster: starrockscluster<br>data:<br>  fe.conf: |<br>    LOG_DIR = ${STARROCKS_HOME}/log<br>    DATE = &quot;$(date +%Y%m%d-%H%M%S)&quot;<br>    JAVA_OPTS=&quot;-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:+UseMembar -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=7 -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -XX:-CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -Xloggc:${LOG_DIR}/fe.gc.log.$DATE&quot;<br>    JAVA_OPTS_FOR_JDK_9=&quot;-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=7 -XX:+CMSClassUnloadingEnabled -XX:-CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -Xlog:gc*:${LOG_DIR}/fe.gc.log.$DATE:time&quot;<br>    JAVA_OPTS_FOR_JDK_11=&quot;-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:+UseG1GC -Xlog:gc*:${LOG_DIR}/fe.gc.log.$DATE:time&quot;<br>    http_port = 8030<br>    rpc_port = 9020<br>    query_port = 9030<br>    edit_log_port = 9010<br>    mysql_service_nio_enabled = true<br>    sys_log_level = INFO<br>    run_mode = shared_data<br>    cloud_native_meta_port = 6090<br>    # 是否允许 StarRocks 使用 FE 配置文件中指定的存储相关属性创建默认存储卷<br>    enable_load_volume_from_conf = true<br>    aws_s3_path = starrocks<br>    aws_s3_region = us-east-1<br>    aws_s3_endpoint = http://minio.minio.svc.cluster.local:9000<br>    aws_s3_access_key = admin<br>    aws_s3_secret_key = password<br><br>---<br># cn config<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: starrockscluster-cn-cm<br>  namespace: starrocks<br>  labels:<br>    cluster: starrockscluster<br>data:<br>  cn.conf: |<br>    sys_log_level = INFO<br>    # ports for admin, web, heartbeat service<br>    thrift_port = 9060<br>    webserver_port = 8040<br>    heartbeat_service_port = 9050<br>    brpc_port = 8060</pre><p><strong>Update Starrocks cluster with root password</strong></p><pre>&gt; kubectl apply -f deployment/starrocks/shared_data_mode_with_root_password.yaml</pre><p>Test StarRocks shared_data_mode</p><pre># Connect to nodeport<br>&gt; mysql --host=172.18.0.4 --port=32755 --user=root --password --ssl=FALSE<br>MySQL [(none)]&gt; create database test;<br>MySQL [(none)]&gt; create table test.tbl1(id int, name varchar(10));<br>MySQL [(none)]&gt; select * from test.tbl1;</pre><p>Data is saved in minio:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lYitZsZTYalgpRuq6ddwnQ.png" /></figure><h4>5. Config and Query Iceberg catalog</h4><pre>mysql --host=172.18.0.4 --port=32755 --user=root --password --ssl=FALSE<br>MySQL [(none)]&gt; CREATE EXTERNAL CATALOG lakehouse PROPERTIES (<br>  &quot;type&quot; = &quot;iceberg&quot;, <br>  &quot;iceberg.catalog.type&quot; = &quot;hive&quot;, <br>  &quot;hive.metastore.uris&quot; = &quot;thrift://hive-metastore.metastore.svc.cluster.local:9083&quot;, <br>  &quot;aws.s3.enable_ssl&quot; = &quot;false&quot;, <br>  &quot;aws.s3.enable_path_style_access&quot; = &quot;true&quot;, <br>  &quot;aws.s3.endpoint&quot; = &quot;http://minio.minio.svc.cluster.local:9000&quot;, <br>  &quot;aws.s3.access_key&quot; = &quot;admin&quot;, <br>  &quot;aws.s3.secret_key&quot; = &quot;password&quot;<br>);<br><br>MySQL [(none)]&gt; show databases from lakehouse;<br>MySQL [(none)]&gt; show tables from lakehouse.jaffle_shop;<br>MySQL [(none)]&gt; select * from lakehouse.jaffle_shop.customers limit 10;</pre><p>Query data from Iceberg on Doris:</p><pre>mysql&gt; show databases from iceberg;<br>mysql&gt; show tables from iceberg.jaffle_shop;<br>mysql&gt; select * from iceberg.jaffle_shop.customers limit 5;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkKLaMRxNSfeJi3QeC61FA.png" /></figure><h4>6. Destroy the Kind cluster</h4><pre>&gt; kind delete cluster --name dev</pre><h3>Conclusion</h3><p>This is the final installment in our series on the Core Components for a Data Platform (Data Lakehouse). In this part, we learned how to deploy:</p><ul><li>Object Storage with MinIO</li><li>Metadata Store with Hive Metastore</li><li>Table Format with Apache Iceberg</li><li>Processing with Trino, Spark Operator, and Spark Connect Server</li><li>Airflow to manage ETL workflows using Trino + dbt, Spark Operation, and Spark Connect Server.</li><li>Apache Doris and StarRocks as Interfaces for integrating with applications that want data on the Lakehouse.</li></ul><p>As you may have noticed, this series has primarily focused on the practical aspects of deploying these technologies in a production environment, rather than exploring the underlying reasons, technical details, or optimal use cases. To gain a deeper understanding of these technologies, you’ll need to consult other resources.</p><p>In reality, you may not need to use all of the technologies mentioned above, or you may need to substitute some of them depending on the specific requirements of your project and the resources you have available.</p><p>In the next part, we will deploy some services that support Realtime processing such as Kafka and Risingwave.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c845f2dc69d3" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-8-main-components-data-warehouse-with-starrocks-c845f2dc69d3">[Kubernetes Data Platform][Part 8][Main Components]: Data warehouse with StarRocks</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 7][Main Components]: Data warehouse with Apache Doris]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-7-main-components-data-warehouse-with-apache-doris-466400b1b23e?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/466400b1b23e</guid>
            <category><![CDATA[trinodb]]></category>
            <category><![CDATA[apache-doris]]></category>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Wed, 07 Aug 2024 06:34:17 GMT</pubDate>
            <atom:updated>2024-08-23T18:28:17.582Z</atom:updated>
            <content:encoded><![CDATA[<p>We’ve nearly completed the core components of a data platform (Data Lakehouse), using MinIO, Hive Metastore, and Iceberg. The remaining challenge is enabling other applications to integrate and utilize data from this lakehouse. While Trino and Spark might come to mind, they aren’t ideal due to their unfamiliarity to most developers, potential integration issues with existing BI tools, and security concerns.</p><p>As a rising star in the real-time data warehouse domain, Apache Doris offers several compelling features. Here’s how it addresses our data platform’s needs:</p><ul><li><strong>Seamless Integration:</strong> Provides a MySQL interface and ANSI SQL compatibility, ensuring easy integration with BI tools. Offers an open data API for external compute engines like Spark, Flink, and ML/AI, and integrates smoothly with backend frameworks (Spring Boot, FastAPI, etc.).</li><li><strong>Federated Querying:</strong> Enables querying data lakes (Hive, Iceberg, Hudi) and databases (MySQL, PostgreSQL) directly, eliminating the need to load data into data marts. This is similar to Trino’s functionality.</li><li><strong>Robust Security:</strong> Implements Role-Based Access Control (RBAC) for granular permission management.</li><li><strong>Real-time Capabilities:</strong> Supports both push-based and pull-based data ingestion, real-time upserts, appends, and pre-aggregation.</li><li><strong>High Performance:</strong> Optimized for high-concurrency and high-throughput queries with columnar storage, MPP architecture, cost-based query optimizer, and vectorized execution engine.</li><li><strong>Data Flexibility:</strong> Handles semi-structured data (arrays, maps, JSON) and offers automatic data type inference for JSON. Includes features for text search.</li><li><strong>Scalability:</strong> Provides a distributed design for linear scalability, workload isolation, tiered storage, and supports both shared-nothing clusters and separation of storage and compute.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jXn6ZrpGUgEG-VoWgopnvw.png" /></figure><h3>DEPLOYMENT STEPS</h3><ol><li><strong>Initialize a Kubernetes cluster with Kind.</strong></li><li><strong>Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino, Apache Airflow on Kubernetes</strong></li><li><strong>Trigger DAG: dbt_jaffle-shop-classic_example</strong></li><li><strong>Install Apache Doris</strong></li><li><strong>Config and Query Iceberg catalog</strong></li><li><strong>Destroy the Kind cluster</strong></li></ol><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/doris/kubernetes">https://github.com/viethqb/data-platform-notes/tree/main/doris/kubernetes</a></p><h4>1. Initialize a Kubernetes cluster with Kind.</h4><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/doris/kubernetes<br>&gt; kind create cluster --name dev --config deployment/kind/kind-config.yaml</pre><h4>2. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino on Kubernetes</h4><p><strong>Install Nginx Ingress Controller</strong></p><pre>&gt; helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>&gt; helm repo update<br>&gt; helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>&gt; kubectl -n ingress-nginx get po -owide</pre><p><strong>Install MinIO</strong></p><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f deployment/minio/minio-values.yaml bitnami/minio --create-namespace --debug --version 14.6.0<br>&gt; kubectl -n minio get po<br>&gt; kubectl get no -owide<br># NAME                STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION   CONTAINER-RUNTIME<br># dev-control-plane   Ready    control-plane   3m53s   v1.30.0   172.18.0.2    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker          Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.5    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker2         Ready    &lt;none&gt;          3m12s   v1.30.0   172.18.0.3    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker3         Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.4    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15</pre><pre># Add the following lines to the end of the /etc/hosts<br>172.18.0.4  minio.lakehouse.local  airflow.lakehouse.local</pre><p><strong>Install Hive Metastore</strong></p><pre># hive-metastore-postgresql<br>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install metastore-db -n metastore -f deployment/hive/hive-metastore-postgres-values.yaml bitnami/postgresql --create-namespace --debug --version 15.4.2<br><br># Hive metastore<br># docker pull rtdl/hive-metastore:3.1.2<br># kind load docker-image rtdl/hive-metastore:3.1.2 --name dev<br>&gt; helm upgrade --install hive-metastore -n metastore -f deployment/hive/hive-metastore-values.yaml ../../charts/hive-metastore --create-namespace --debug</pre><p><strong>Install Trino</strong></p><pre>&gt; helm repo add trino https://trinodb.github.io/charts<br>&gt; helm upgrade --install trino -n trino -f deployment/trino/trino-values.yaml trino/trino --create-namespace --debug --version 0.21.0<br>&gt; kubectl -n trino get po</pre><p><strong>Install Apache Airflow</strong></p><pre>&gt; helm repo add airflow https://airflow.apache.org/<br>&gt; helm repo update<br>&gt; helm upgrade --install airflow airflow/airflow -f deployment/airflow/airflow-values.yaml --namespace airflow --create-namespace --debug --version 1.13.1 --timeout 600s<br>&gt; kubectl -n airflow get po</pre><p>Access at <a href="http://airflow.lakehouse.local/connection/list/">http://airflow.lakehouse.local/connection/list/</a> ⇒ user: admin &amp; password: admin</p><p><strong>Config S3 Connection and Kubernetes Connection in Airflow UI</strong></p><p>Access Airflow Connection at <a href="http://airflow.lakehouse.local/connection/list/">http://airflow.lakehouse.local/connection/list/</a> ⇒ add new record</p><pre>Connection Id: s3_default<br>Connection Type: Amazon Web Services<br>AWS Access Key ID: admin <br>AWS Secret Access Key: password<br>Extra: {&quot;endpoint_url&quot;: &quot;&lt;http://minio.minio.svc.cluster.local:9000&gt;&quot;}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PVAebL5bZs-fYnEh8Y62w.png" /></figure><pre>Connection Id: kubernetes_default<br>Connection Type: Kubernetes Cluster Connection<br>In cluster configuration: yes<br>Disable SSL: yes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmaPb9Sg_H26JJ9dSvBbkg.png" /></figure><h3>3. Trigger DAG: dbt_jaffle-shop-classic_example</h3><p>Create jaffle_shop schema:</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; CREATE SCHEMA lakehouse.jaffle_shop WITH (location = &#39;s3a://lakehouse/jaffle_shop.db/&#39;);</pre><p>Access at <a href="http://airflow.lakehouse.local/dags/dbt_jaffle-shop-classic_example/grid">http://airflow.lakehouse.local/dags/dbt_jaffle-shop-classic_example/grid</a> ⇒ Trigger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kuhx7_aNXoh2ih7_gqaR9A.png" /></figure><p>Check tables from jaffle_shop schema:</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; show tables from lakehouse.jaffle_shop;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAwa6BOvOkjJmDlVzXiXGA.png" /></figure><h3>4. Install Apache Doris</h3><p>Install doris-operator ⇒ Custom resource: <strong>dorisclusters.doris.selectdb.com</strong></p><pre>helm repo add doris https://charts.selectdb.com/<br>helm repo update<br>helm upgrade --install operator doris/doris-operator --namespace doris --create-namespace --debug --version 1.6.0</pre><p><strong>doriscluster-sample-storageclass.yaml</strong></p><pre># This yaml describe using `storageclass` to provide persistentVolume for fe and be.<br># This yaml use default `storageclass` on kubernetes. when use specific storageclass please update then field of storageClassName.<br>apiVersion: doris.selectdb.com/v1<br>kind: DorisCluster<br>metadata:<br>  labels:<br>    app.kubernetes.io/name: doriscluster<br>    app.kubernetes.io/instance: doriscluster-sample-storageclass<br>    app.kubernetes.io/part-of: doris-operator<br>  name: doriscluster-sample-storageclass1<br>  namespace: doris<br>spec:<br>  adminUser:<br>    name: root<br>    password: &quot;12345678&quot;<br>  feSpec:<br>    replicas: 3<br>    image: selectdb/doris.fe-ubuntu:2.1.2<br>    service:<br>      type: NodePort<br>      servicePorts:<br>        - nodePort: 31001<br>          targetPort: 8030<br>        - nodePort: 31002<br>          targetPort: 8040<br>        - nodePort: 31003<br>          targetPort: 9030<br>    # limits:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # requests:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    persistentVolumes:<br>      - mountPath: /opt/apache-doris/fe/doris-meta<br>        name: fetest<br>        persistentVolumeClaimSpec:<br>          # when use specific storageclass, the storageClassName should reConfig, example as annotation.<br>          #storageClassName: openebs-jiva-csi-default<br>          accessModes:<br>            - ReadWriteOnce<br>          resources:<br>            # notice: if the storage size less 5G, fe will not start normal.<br>            requests:<br>              storage: 10Gi<br>      - mountPath: /opt/apache-doris/fe/log<br>        name: felog<br>        persistentVolumeClaimSpec:<br>          # when use specific storageclass, the storageClassName should reConfig, example as annotation.<br>          #storageClassName: openebs-jiva-csi-default<br>          accessModes:<br>            - ReadWriteOnce<br>          resources:<br>            requests:<br>              storage: 10Gi<br>  beSpec:<br>    replicas: 3<br>    image: selectdb/doris.be-ubuntu:2.1.2<br>    # limits:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    # requests:<br>    #   cpu: 2<br>    #   memory: 4Gi<br>    persistentVolumes:<br>      - mountPath: /opt/apache-doris/be/storage<br>        name: betest<br>        persistentVolumeClaimSpec:<br>          # when use specific storageclass, the storageClassName should reConfig, example as annotation.<br>          #storageClassName: openebs-jiva-csi-default<br>          accessModes:<br>            - ReadWriteOnce<br>          resources:<br>            requests:<br>              storage: 10Gi<br>      - mountPath: /opt/apache-doris/be/log<br>        name: belog<br>        persistentVolumeClaimSpec:<br>          # when use specific storageclass, the storageClassName should reConfig, example as annotation.<br>          #storageClassName: openebs-jiva-csi-default<br>          accessModes:<br>            - ReadWriteOnce<br>          resources:<br>            requests:<br>              storage: 10Gi</pre><p>Create Doris cluster using Custom resource: <strong>dorisclusters</strong></p><pre>kubectl apply -f deployment/doris/doriscluster-sample-storageclass.yaml<br>kubectl -n doris get po -owide<br>kubectl -n doris get dorisclusters.doris.selectdb.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-ia1gxPk0gjOfgCFO6I0w.png" /></figure><p>Change Doris password:</p><pre>&gt; kubectl run mysql-client --image=mysql:5.7 -it --rm --restart=Never --namespace=doris -- /bin/bash<br>mysql -uroot -P9030 -hdoriscluster-sample-storageclass1-fe-service<br>mysql&gt; SET PASSWORD FOR &#39;root&#39; = PASSWORD(&#39;12345678&#39;);<br>mysql&gt; SET PASSWORD FOR &#39;admin&#39; = PASSWORD(&#39;12345678&#39;);</pre><h4>5. Config and Query Iceberg catalog</h4><pre>&gt; kubectl -n doris delete po mysql-client<br>&gt; kubectl -n metastore get svc<br>&gt; kubectl -n minio get svc<br>&gt; kubectl run mysql-client --image=mysql:5.7 -it --rm --restart=Never --namespace=doris -- /bin/bash<br>bash-4.2# mysql -uroot -P9030 -hdoriscluster-sample-storageclass1-fe-service -p<br># Using dns not work =&gt; using ip<br>mysql&gt; CREATE CATALOG iceberg PROPERTIES (<br>    &quot;type&quot;=&quot;iceberg&quot;,<br>    &quot;iceberg.catalog.type&quot;=&quot;hms&quot;,<br>    &quot;hive.metastore.uris&quot; = &quot;thrift://10.96.86.185:9083&quot;,<br>    &quot;warehouse&quot; = &quot;s3://lakehouse&quot;,<br>    &quot;s3.access_key&quot; = &quot;admin&quot;,<br>    &quot;s3.secret_key&quot; = &quot;password&quot;,<br>    &quot;s3.endpoint&quot; = &quot;http://10.96.130.201:9000&quot;,<br>    &quot;s3.region&quot; = &quot;us-east-1&quot;<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5heIBbSYhvhu8I3o-AfuLA.png" /></figure><p>Query data from Iceberg on Doris:</p><pre>mysql&gt; show databases from iceberg;<br>mysql&gt; show tables from iceberg.jaffle_shop;<br>mysql&gt; select * from iceberg.jaffle_shop.customers limit 5;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*afrlJQIKnyOJvY5QvXaGyw.png" /></figure><h4>6. Destroy the Kind cluster</h4><pre>&gt; kind delete cluster --name dev</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=466400b1b23e" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-7-main-components-data-warehouse-with-apache-doris-466400b1b23e">[Kubernetes Data Platform][Part 7][Main Components]: Data warehouse with Apache Doris</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 6][Main Components]: Data Orchestrate with Apache Airflow]]></title>
            <link>https://viet1846.medium.com/kubernetes-data-platform-part-6-main-components-data-orchestrate-with-apache-airflow-16407dcb991b?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/16407dcb991b</guid>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[trinodb]]></category>
            <category><![CDATA[data-orchestration]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[apache-airflow]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Wed, 07 Aug 2024 00:19:30 GMT</pubDate>
            <atom:updated>2024-08-22T02:43:08.153Z</atom:updated>
            <content:encoded><![CDATA[<p>In previous sections, we’ve explored how to utilize Trino and Spark for data processing on our data platform. Another crucial aspect of data management is <em>Data Orchestration</em>. Data orchestration is the automated process of gathering siloed data from various storage locations, combining and organizing it, and making it available for analysis. Numerous tools are available for this purpose, and in this article, we’ll delve into deploying Airflow on Kubernetes to manage ETL workflows using Spark Operator, Spark Connect Server, and dbt + Trino.</p><p>Airflow is a powerful tool with diverse deployment options. Here, we’ll present an approach that we consider particularly compelling.</p><p>Our Airflow setup will utilize Kubernetes with the following configurations:</p><p><strong>Executor:</strong> The Kubernetes executor runs each task instance in its own pod on a Kubernetes cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I65lWXrQ0iCSzOOUTXizrA.png" /></figure><p><strong>Logging:</strong> Before terminating a Pod, Airflow pushes logs to Minio, enabling us to debug issues that arise.</p><p><strong>GitSync: </strong>GitSync streamlines DAG development and deployment for Airflow environments by automatically syncing pipeline code from Git to Airflow’s DAG folder. This eliminates manual synchronization and simplifies the CI/CD process.</p><p><strong>Key Benefits of GitSync:</strong></p><ul><li>Automated DAG deployment</li><li>Streamlined development workflow</li><li>Simplified CI/CD</li><li>Reduced development time</li><li>Improved code quality</li><li>Enhanced collaboration</li><li>Simplified deployment</li></ul><p><strong>How GitSync Works:</strong></p><ol><li>Develop DAGs in Git</li><li>Commit and push changes</li><li>GitSync automatically deploys</li></ol><p><strong>Embrace Automated DAG Deployment with GitSync</strong></p><ul><li>GitSync simplifies DAG management and revolutionizes pipeline deployment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TyKaqjJWpWlVdzCUT-N2kA.png" /></figure><h3>DEPLOYMENT STEPS</h3><ol><li>Initialize a Kubernetes cluster with Kind.</li><li>Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino, Spark Operator and Spark Connect Server on Kubernetes</li><li>Install Apache Airflow</li><li>Airflow with Spark Connect Server</li><li>Airflow with Spark Operator</li><li>Airflow with Trino + dbt</li><li>Destroy the Kind cluster</li></ol><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/airflow">https://github.com/viethqb/data-platform-notes/tree/main/airflow</a></p><h4>1. Initialize a Kubernetes cluster with Kind.</h4><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/airflow<br>&gt; kind create cluster --name dev --config deployment/kind/kind-config.yaml</pre><h4>2. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino, Spark Operator and Spark Connect Server on Kubernetes</h4><p><strong>Install Nginx Ingress Controller</strong></p><pre>&gt; helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>&gt; helm repo update<br>&gt; helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>&gt; kubectl -n ingress-nginx get po -owide</pre><p><strong>Install MinIO</strong></p><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f deployment/minio/minio-values.yaml bitnami/minio --create-namespace --debug --version 14.6.0<br>&gt; kubectl -n minio get po<br>&gt; kubectl get no -owide<br># NAME                STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION   CONTAINER-RUNTIME<br># dev-control-plane   Ready    control-plane   3m53s   v1.30.0   172.18.0.2    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker          Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.5    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker2         Ready    &lt;none&gt;          3m12s   v1.30.0   172.18.0.3    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker3         Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.4    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15</pre><pre># Add the following lines to the end of the /etc/hosts<br># 172.18.0.4  minio.lakehouse.local  airflow.lakehouse.local</pre><p>Download and Upload file <a href="https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2009-01.parquet">https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2009-01.parquet</a> to s3a://lakehouse/raw.db/yellow_tripdata/y=2009/m=01/yellow_tripdata_2009-01.parquet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCYSxTKLAb-JjnLFetDcpw.png" /></figure><p><strong>Install Hive Metastore</strong></p><pre># hive-metastore-postgresql<br>&gt; helm repo add bitnami &lt;https://charts.bitnami.com/bitnami&gt;<br>&gt; helm repo update<br>&gt; helm upgrade --install metastore-db -n metastore -f deployment/hive/hive-metastore-postgres-values.yaml bitnami/postgresql --create-namespace --debug --version 15.4.2<br><br># Hive metastore<br># docker pull rtdl/hive-metastore:3.1.2<br># kind load docker-image rtdl/hive-metastore:3.1.2 --name dev<br>&gt; helm upgrade --install hive-metastore -n metastore -f deployment/hive/hive-metastore-values.yaml ../../charts/hive-metastore --create-namespace --debug</pre><p><strong>Install Trino</strong></p><pre>&gt; helm repo add trino https://trinodb.github.io/charts<br>&gt; helm upgrade --install trino -n trino -f deployment/trino/trino-values.yaml trino/trino --create-namespace --debug --version 0.21.0<br>&gt; kubectl -n trino get po</pre><p><strong>Install Spark Operator</strong></p><pre>&gt; helm repo add spark-operator https://kubeflow.github.io/spark-operator <br>&gt; helm repo update<br>&gt; helm upgrade --install spark-operator spark-operator/spark-operator --namespace spark-operator --set webhook.enable=true --set image.tag=v1beta2-1.4.6-3.5.0 --create-namespace --debug --version 1.3.2 <br>&gt; kubectl -n spark-operator get po</pre><p><strong>Install Spark Connect Server</strong></p><pre>&gt; kubectl create ns sparglim<br>&gt; kubectl create clusterrolebinding serviceaccounts-cluster-admin --clusterrole=cluster-admin --group=system:serviceaccounts<br>&gt; kubectl apply -f deployment/spark-connect-server/<br>&gt; kubectl -n sparglim logs -f deployments/sparglim-server</pre><h4>3. Install Apache Airflow</h4><p><strong>viet1846/airflow:2.8.3 Dockerfile</strong></p><pre>FROM apache/airflow:2.8.3<br>USER airflow<br>COPY requirements.txt .<br>RUN python3 -m pip install --upgrade pip<br>RUN python3 -m pip install --no-cache-dir -r requirements.txt</pre><p><strong>requirements.txt</strong></p><pre>pandas==2.0.3<br>dbt-core==1.8.2<br>dbt-trino==1.8.0<br>astronomer-cosmos==1.4.3<br>apache-airflow-providers-trino==5.7.1<br>apache-airflow-providers-cncf-kubernetes==7.13.0<br>pyspark==3.4.1 <br>grpcio-status <br>pyarrow</pre><p><strong>airflow-values.yaml</strong></p><pre>defaultAirflowRepository: viet1846/airflow<br><br>defaultAirflowTag: &quot;2.8.3&quot;<br><br>airflowVersion: &quot;2.8.3&quot;<br>images:<br>  airflow:<br>    pullPolicy: Always<br># Select certain nodes for airflow pods.<br>nodeSelector: {}<br>affinity: {}<br>tolerations: []<br>topologySpreadConstraints: []<br>schedulerName: ~<br><br># Ingress configuration<br>ingress:<br>  enabled: ~<br>  web:<br>    # Enable web ingress resource<br>    enabled: true<br><br>    # Annotations for the web Ingress<br>    annotations: {}<br><br>    # The path for the web Ingress<br>    path: &quot;/&quot;<br><br>    # The pathType for the above path (used only with Kubernetes v1.19 and above)<br>    pathType: &quot;ImplementationSpecific&quot;<br><br>    # The hostname for the web Ingress (Deprecated - renamed to `ingress.web.hosts`)<br>    host: &quot;airflow.lakehouse.local&quot;<br><br>    # The hostnames or hosts configuration for the web Ingress<br>    hosts: []<br>    #   # The hostname for the web Ingress (can be templated)<br>    # - name: &quot;&quot;<br>    #   # configs for web Ingress TLS<br>    #   tls:<br>    #     # Enable TLS termination for the web Ingress<br>    #     enabled: false<br>    #     # the name of a pre-created Secret containing a TLS private key and certificate<br>    #     secretName: &quot;&quot;<br><br>    # The Ingress Class for the web Ingress (used only with Kubernetes v1.19 and above)<br>    ingressClassName: &quot;nginx&quot;<br><br>    # configs for web Ingress TLS (Deprecated - renamed to `ingress.web.hosts[*].tls`)<br>    tls:<br>      # Enable TLS termination for the web Ingress<br>      enabled: false<br>      # the name of a pre-created Secret containing a TLS private key and certificate<br>      secretName: &quot;&quot;<br><br>    # HTTP paths to add to the web Ingress before the default path<br>    precedingPaths: []<br><br>    # Http paths to add to the web Ingress after the default path<br>    succeedingPaths: []<br><br>executor: &quot;KubernetesExecutor&quot;<br><br>extraEnv: |<br>  - name: AIRFLOW__CORE__DAGS_FOLDER<br>    value: &#39;/opt/airflow/dags/repo/airflow/dags&#39;<br>  - name: AIRFLOW__CORE__DEFAULT_TIMEZONE<br>    value: &#39;Asia/Ho_Chi_Minh&#39;<br>  - name: AIRFLOW__CORE__DAGBAG_IMPORT_TIMEOUT<br>    value: &#39;300&#39;<br>  - name: AIRFLOW__SCHEDULER__PARSING_CLEANUP_INTERVAL<br>    value: &#39;30&#39;<br><br># Airflow database &amp; redis config<br>data:<br>  # Otherwise pass connection values in<br>  metadataConnection:<br>    user: postgres<br>    pass: postgres<br>    protocol: postgresql<br>    host: ~<br>    port: 5432<br>    db: postgres<br>    sslmode: disable<br><br>webserverSecretKey: 2cbfd5b635391cae990a3b0e7553a68e<br><br>scheduler:<br>  enabled: true<br>  hostAliases: []<br>  #  - ip: &quot;127.0.0.1&quot;<br>  #    hostnames:<br>  #      - &quot;foo.local&quot;<br>  #  - ip: &quot;10.1.2.3&quot;<br>  #    hostnames:<br>  #      - &quot;foo.remote&quot;<br>  replicas: 1<br>  resources: {}<br>  #  limits:<br>  #   cpu: 100m<br>  #   memory: 128Mi<br>  #  requests:<br>  #   cpu: 100m<br>  #   memory: 128Mi<br>  nodeSelector: {}<br><br># Airflow database migration job settings<br>migrateDatabaseJob:<br>  enabled: true<br><br># Airflow webserver settings<br>webserver:<br>  enabled: true<br>  replicas: 1<br>  resources: {}<br>  #   limits:<br>  #     cpu: 100m<br>  #     memory: 128Mi<br>  #   requests:<br>  #     cpu: 100m<br>  #     memory: 128Mi<br><br>  defaultUser:<br>    enabled: true<br>    role: Admin<br>    username: admin<br>    email: admin@example.com<br>    firstName: admin<br>    lastName: user<br>    password: admin<br>  nodeSelector: {}<br>  env: []<br><br>triggerer:<br>  enabled: true<br>  replicas: 1<br>  persistence:<br>    enabled: true<br>    size: 100Gi<br>  resources: {}<br>  #  limits:<br>  #   cpu: 100m<br>  #   memory: 128Mi<br>  #  requests:<br>  #   cpu: 100m<br>  #   memory: 128Mi<br>  nodeSelector: {}<br>  affinity: {}<br>  env: []<br><br># StatsD settings<br>statsd:<br>  enabled: true<br>  resources: {}<br>  #   limits:<br>  #     cpu: 100m<br>  #     memory: 128Mi<br>  #   requests:<br>  #     cpu: 100m<br>  #     memory: 128Mi<br>  nodeSelector: {}<br>  env: []<br><br>redis:<br>  enabled: false<br><br># Not recommended for production<br>postgresql:<br>  enabled: true<br>  auth:<br>    enablePostgresUser: true<br>    postgresPassword: postgres<br>    username: &quot;admin&quot;<br>    password: &quot;admin&quot;<br><br>config:<br>  logging:<br>    remote_logging: &quot;True&quot;<br>    remote_base_log_folder: &quot;s3://airflow/logs&quot;<br>    remote_log_conn_id: &quot;s3_default&quot;<br>    encrypt_s3_logs: &quot;False&quot;<br># Git sync<br>dags:<br>  gitSync:<br>    enabled: true<br><br>    repo: https://github.com/viethqb/data-platform-notes.git<br>    branch: main<br>    rev: HEAD<br>    depth: 1<br>    subPath: &quot;airflow&quot;<br>    # if your repo needs a user name password<br>    # you can load them to a k8s secret like the one below<br>    #   ---<br>    #   apiVersion: v1<br>    #   kind: Secret<br>    #   metadata:<br>    #     name: git-credentials<br>    #   data:<br>    #     # For git-sync v3<br>    #     GIT_SYNC_USERNAME: &lt;base64_encoded_git_username&gt;<br>    #     GIT_SYNC_PASSWORD: &lt;base64_encoded_git_password&gt;<br>    #     # For git-sync v4<br>    #     GITSYNC_USERNAME: &lt;base64_encoded_git_username&gt;<br>    #     GITSYNC_PASSWORD: &lt;base64_encoded_git_password&gt;<br>    # and specify the name of the secret below<br>    #<br>    # credentialsSecret: git-credentials<br>    #<br>    #<br>    # If you are using an ssh clone url, you can load<br>    # the ssh private key to a k8s secret like the one below<br>    #   ---<br>    #   apiVersion: v1<br>    #   kind: Secret<br>    #   metadata:<br>    #     name: airflow-ssh-secret<br>    #   data:<br>    #     # key needs to be gitSshKey<br>    #     gitSshKey: &lt;base64_encoded_data&gt;<br>    # and specify the name of the secret below<br>    # sshKeySecret: airflow-ssh-secret<br>    #<br>    # If you are using an ssh private key, you can additionally<br>    # specify the content of your known_hosts file, example:<br>    #<br>    # knownHosts: |<br>    #    &lt;host1&gt;,&lt;ip1&gt; &lt;key1&gt;<br>    #    &lt;host2&gt;,&lt;ip2&gt; &lt;key2&gt;</pre><p>Install Airflow on Kubernetes</p><pre># docker build -t viet1846/airflow:2.8.3 .<br># docker push viet1846/airflow:2.8.3<br>&gt; helm repo add airflow &lt;https://airflow.apache.org/&gt;<br>&gt; helm repo update<br>&gt; helm upgrade --install airflow airflow/airflow -f deployment/airflow/airflow-values.yaml --namespace airflow --create-namespace --debug --version 1.13.1 --timeout 600s<br>&gt; kubectl -n airflow get po</pre><p>Access Airflow at <a href="http://airflow.lakehouse.local/connection/list/">http://airflow.lakehouse.local/connection/list/</a> with user: admin &amp; password: admin</p><p><strong>Config S3 Connection and Kubernetes Connection in Airflow UI</strong></p><p>Access Airflow Connection at <a href="http://airflow.lakehouse.local/connection/list/">http://airflow.lakehouse.local/connection/list/</a> ⇒ add new record</p><pre>Connection Id: s3_default<br>Connection Type: Amazon Web Services<br>AWS Access Key ID: admin <br>AWS Secret Access Key: password<br>Extra: {&quot;endpoint_url&quot;: &quot;http://minio.minio.svc.cluster.local:9000&quot;}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PVAebL5bZs-fYnEh8Y62w.png" /></figure><pre>Connection Id: kubernetes_default<br>Connection Type: Kubernetes Cluster Connection<br>In cluster configuration: yes<br>Disable SSL: yes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmaPb9Sg_H26JJ9dSvBbkg.png" /></figure><p><strong>Config Airflow permission to submit Spark job (Spark Operator)</strong></p><pre>&gt; kubectl create role spark-operator-submitter --verb=create,get --resource=sparkapplications,pods/log --namespace=spark-operator<br>&gt; kubectl create rolebinding airflow-worker-spark-submitter --role=spark-operator-submitter --serviceaccount=airflow:airflow-worker --namespace=spark-operator</pre><h4>4. Airflow with Spark Connect Server</h4><p>Code: <a href="https://github.com/viethqb/data-platform-notes/blob/main/airflow/dags/spark_connect_server_example.py">https://github.com/viethqb/data-platform-notes/blob/main/airflow/dags/spark_connect_server_example.py</a></p><pre>from __future__ import print_function<br>from builtins import range<br>from airflow.operators.empty import EmptyOperator<br>from airflow.operators.python_operator import PythonOperator<br>from airflow.models import DAG<br>from pyspark.sql import SparkSession<br>from datetime import datetime, date, timedelta<br>from pyspark.sql import Row<br>import os<br>import time<br>from pprint import pprint<br><br>seven_days_ago = datetime.combine(datetime.today() - timedelta(7), datetime.min.time())<br><br>args = {<br>    &quot;owner&quot;: &quot;airflow&quot;,<br>    &quot;start_date&quot;: seven_days_ago,<br>}<br><br>dag = DAG(<br>    dag_id=&quot;spark_connect_server_example&quot;, default_args=args, schedule_interval=None<br>)<br><br><br>def spark_connect_server_example():<br>    SPARK_CONNECT_SERVER = (<br>        &quot;sc://sparglim-server-service.sparglim.svc.cluster.local:15002&quot;<br>    )<br>    spark = SparkSession.builder.remote(SPARK_CONNECT_SERVER).getOrCreate()<br><br>    df = spark.createDataFrame(<br>        [<br>            Row(<br>                a=1,<br>                b=2.0,<br>                c=&quot;string1&quot;,<br>                d=date(2000, 1, 1),<br>                e=datetime(2000, 1, 1, 12, 0),<br>            ),<br>            Row(<br>                a=2,<br>                b=3.0,<br>                c=&quot;string2&quot;,<br>                d=date(2000, 2, 1),<br>                e=datetime(2000, 1, 2, 12, 0),<br>            ),<br>            Row(<br>                a=4,<br>                b=5.0,<br>                c=&quot;string3&quot;,<br>                d=date(2000, 3, 1),<br>                e=datetime(2000, 1, 3, 12, 0),<br>            ),<br>        ]<br>    )<br>    df.show()<br><br>    create_schema_df = spark.sql(&quot;CREATE DATABASE IF NOT EXISTS raw &quot;)<br><br>    df.writeTo(&quot;raw.demo&quot;).tableProperty(<br>        &quot;write.format.default&quot;, &quot;parquet&quot;<br>    ).createOrReplace()<br><br><br>start = EmptyOperator(<br>    task_id=&quot;start&quot;,<br>    dag=dag,<br>)<br><br>end = EmptyOperator(<br>    task_id=&quot;end&quot;,<br>    dag=dag,<br>)<br><br>spark_connect_server_example = PythonOperator(<br>    task_id=&quot;spark_connect_server_example&quot;,<br>    provide_context=True,<br>    python_callable=spark_connect_server_example,<br>    dag=dag,<br>)<br>start &gt;&gt; spark_connect_server_example &gt;&gt; end</pre><p>Link DAG: <a href="http://airflow.lakehouse.local/dags/spark_connect_server_example/grid">http://airflow.lakehouse.local/dags/spark_connect_server_example/grid</a></p><p>Trigger DAG:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*23fSdGGdYMhZa03Au7AZaw.png" /></figure><p>Using Trino query Iceberg table created by Spark Connect Server</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; select * from lakehouse.raw.demo;</pre><h4>5. Airflow with Spark Operator</h4><p>Code: <a href="https://github.com/viethqb/data-platform-notes/blob/main/airflow/dags/spark_main_iceberg.py">https://github.com/viethqb/data-platform-notes/blob/main/airflow/dags/spark_main_iceberg.py</a></p><pre>from datetime import timedelta, datetime<br><br># [START import_module]<br># The DAG object; we&#39;ll need this to instantiate a DAG<br>from airflow import DAG<br><br># Operators; we need this to operate!<br>from airflow.providers.cncf.kubernetes.operators.spark_kubernetes import (<br>    SparkKubernetesOperator,<br>)<br>from airflow.providers.cncf.kubernetes.sensors.spark_kubernetes import (<br>    SparkKubernetesSensor,<br>)<br>from airflow.utils.dates import days_ago<br><br># [END import_module]<br><br># [START default_args]<br># These args will get passed on to each operator<br># You can override them on a per-task basis during operator initialization<br>default_args = {<br>    &quot;owner&quot;: &quot;airflow&quot;,<br>    &quot;depends_on_past&quot;: False,<br>    &quot;start_date&quot;: days_ago(1),<br>    &quot;email&quot;: [&quot;airflow@example.com&quot;],<br>    &quot;email_on_failure&quot;: False,<br>    &quot;email_on_retry&quot;: False,<br>    &quot;max_active_runs&quot;: 1,<br>    &quot;retries&quot;: 3,<br>}<br># [END default_args]<br><br>dag = DAG(<br>    &quot;spark_main_iceberg&quot;,<br>    default_args=default_args,<br>    schedule_interval=None,<br>    tags=[&quot;example&quot;, &quot;spark&quot;],<br>)<br><br>submit = SparkKubernetesOperator(<br>    task_id=&quot;main_iceberg_submit&quot;,<br>    namespace=&quot;spark-operator&quot;,<br>    application_file=&quot;spark_jobs/main_iceberg.yaml&quot;,<br>    kubernetes_conn_id=&quot;kubernetes_default&quot;,<br>    do_xcom_push=True,<br>    dag=dag,<br>)<br><br>sensor = SparkKubernetesSensor(<br>    task_id=&quot;main_iceberg_monitor&quot;,<br>    namespace=&quot;spark-operator&quot;,<br>    application_name=&quot;{{ task_instance.xcom_pull(task_ids=&#39;main_iceberg_submit&#39;)[&#39;metadata&#39;][&#39;name&#39;] }}&quot;,<br>    kubernetes_conn_id=&quot;kubernetes_default&quot;,<br>    dag=dag,<br>    attach_log=True,<br>)<br><br>submit &gt;&gt; sensor</pre><p>Link DAG: <a href="http://airflow.lakehouse.local/dags/spark_main_iceberg/grid">http://airflow.lakehouse.local/dags/spark_main_iceberg/grid</a></p><p>Trigger DAG:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NzyxqW597O84J8Uhyn-PPA.png" /></figure><p>Running Pod:</p><pre>&gt; kubectl -n spark-operator get po</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-KrAQojxWwEhLPwkZF_zOw.png" /></figure><p>Using Trino query Iceberg table created by Spark Operator</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; select * from lakehouse.raw.taxis_spark limit 10;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7OI5HvcfBHhi3KSYFw5g9w.png" /></figure><h3>6. Airflow with Trino + dbt</h3><p>The idea of this project is to demonstrate the power of two of the most successful Open Source data projects, dbt and Trino:</p><ul><li>dbt (data build tool) enables analytics engineers to transform data in their warehouses by simply writing SQL select statements. dbt handles turning these SQL select statements into tables and views.</li><li>Trino, formerly PrestoSQL, is a fast distributed SQL query engine for big data analytics that helps you explore your data universe and mix multiple data sources.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-dwbyUC_qMsnZnxGdCEhA.png" /></figure><h4><strong>Run dbt Projects Seamlessly with Airflow using Astronomer Cosmos</strong></h4><p><a href="https://github.com/astronomer/astronomer-cosmos">Astronomer Cosmos</a> simplifies integrating dbt Core projects with Apache Airflow. With just a few lines of code, you can execute dbt models as Airflow DAGs and Task Groups.</p><p>Run your dbt Core projects as <strong><em>Apache Airflow</em></strong> DAGs and Task Groups with a few lines of code. Benefits include:</p><ul><li>Run dbt projects against Airflow connections instead of dbt profiles</li><li>Native support for installing and running dbt in a virtual environment to avoid dependency conflicts with Airflow</li><li>Run tests immediately after a model is done to catch issues early</li><li>Utilize Airflow’s data-aware scheduling to run models immediately after upstream ingestion</li><li>Turn each dbt model into a task/task group complete with retries, alerting, etc.</li></ul><p>For this demonstration, I’ll be utilizing the <a href="https://github.com/viethqb/data-platform-notes/tree/main/airflow/dbt/jaffle-shop-classic">jaffle-shop-classic</a> project.</p><p>The <a href="https://github.com/viethqb/data-platform-notes/blob/main/airflow/dbt/jaffle-shop-classic/profiles.yml">profiles.yml</a> file houses database connection details. However, due to security considerations, these credentials cannot be stored directly in the Git repository. Instead, they will be passed as Environment Variables.</p><p><em>We can leverage airflow secret to manage and transfer these sensitive parameters securely. (Not in this lab)</em></p><p><strong>profiles.yml</strong></p><pre>trino:<br>  target: dev<br>  outputs:<br>    dev:<br>      type: trino<br>      method: none<br>      user: &quot;{{ env_var(&#39;TRINO_USER&#39;) }}&quot;<br>      host: &quot;{{ env_var(&#39;TRINO_HOST&#39;) }}&quot;<br>      port: &quot;{{ env_var(&#39;TRINO_PORT&#39;) | int }}&quot;<br>      http_scheme: http<br>      database: lakehouse<br>      schema: jaffle_shop</pre><p>Code: <a href="https://github.com/viethqb/data-platform-notes/blob/main/airflow/dags/dbt_jaffle-shop-classic.py">https://github.com/viethqb/data-platform-notes/blob/main/airflow/dags/dbt_jaffle-shop-classic.py</a></p><pre>from pathlib import Path<br>from datetime import datetime<br>from cosmos import DbtDag, ProjectConfig, ProfileConfig<br>from cosmos import ExecutionConfig<br><br>jaffle_shop_path = Path(&quot;/opt/airflow/dags/repo/airflow/dbt/jaffle-shop-classic&quot;)<br>dbt_executable = Path(&quot;/home/airflow/.local/bin/dbt&quot;)<br><br>venv_execution_config = ExecutionConfig(<br>    dbt_executable_path=str(dbt_executable),<br>)<br><br><br>dbt_profile_example = DbtDag(<br>    # dbt/cosmos-specific parameters<br>    project_config=ProjectConfig(<br>        dbt_project_path=jaffle_shop_path,<br>        env_vars={<br>            &quot;TRINO_HOST&quot;: &quot;trino.trino.svc.cluster.local&quot;,<br>            &quot;TRINO_PORT&quot;: &quot;8080&quot;,<br>            &quot;TRINO_USER&quot;: &quot;dbt&quot;,<br>        },<br>    ),<br>    profile_config=ProfileConfig(<br>        # these map to dbt/jaffle_shop/profiles.yml<br>        profile_name=&quot;trino&quot;,<br>        target_name=&quot;dev&quot;,<br>        profiles_yml_filepath=jaffle_shop_path / &quot;profiles.yml&quot;,<br>    ),<br>    execution_config=venv_execution_config,<br>    # normal dag parameters<br>    schedule_interval=&quot;@daily&quot;,<br>    start_date=datetime(2023, 1, 1),<br>    catchup=False,<br>    dag_id=&quot;dbt_jaffle-shop-classic_example&quot;,<br>    tags=[&quot;dbt&quot;],<br>)</pre><p>Link DAG: <a href="http://airflow.lakehouse.local/dags/dbt_jaffle-shop-classic_example/grid">http://airflow.lakehouse.local/dags/dbt_jaffle-shop-classic_example/grid</a></p><p>Create jaffle_shop schema:</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; CREATE SCHEMA lakehouse.jaffle_shop WITH (location = &#39;s3a://lakehouse/jaffle_shop.db/&#39;);</pre><p>Trigger DAG:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJP1IKr7bRYzISz_zpN_lw.png" /></figure><p>Running Pod:</p><pre>&gt; kubectl -n airflow get po</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bc86bVEumtG0755Kj1x3Og.png" /></figure><p>Using Trino query Iceberg table created by bdt + Trino</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; show tables from lakehouse.jaffle_shop;<br>trino&gt; select * from lakehouse.jaffle_shop.customers limit 5;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gF60zUDbKw2THMUp-GvlAg.png" /></figure><h4>7. Destroy the Kind cluster</h4><pre>&gt; kind delete cluster --name dev</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16407dcb991b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 5.2][Main Components]: Apache Spark with Spark Connect Server]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-5-2-main-components-apache-spark-with-spark-connect-server-608861b262ed?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/608861b262ed</guid>
            <category><![CDATA[spark-on-kubernetes]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[spark-connect]]></category>
            <category><![CDATA[data-lakehouse]]></category>
            <category><![CDATA[spark-on-k8s]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Tue, 06 Aug 2024 16:07:59 GMT</pubDate>
            <atom:updated>2024-08-23T18:28:22.815Z</atom:updated>
            <content:encoded><![CDATA[<p>In Part 5.1, I discussed how to deploy SparkApplications on a Kubernetes environment using Spark Operator. This involved integrating Spark with Hive Metastore, MinIO, and Iceberg.</p><p>The development process for SparkApplications using Spark Operator involves the following steps:</p><ol><li>Develop SparkApplications according to business requirements.</li><li>Write a Manifest file describing the SparkApplications.</li><li>Build a dev Docker image.</li><li>Submit SparkApplications through Spark Operator for testing.</li><li>Repeat steps 1–4 until the application passes.</li><li>Merge code and build a production image.</li><li>Schedule SparkApplications to run (daily, hourly, etc.) using data orchestration tools.</li></ol><p>To ensure a smooth workflow, it’s crucial to set up CI/CD pipelines. This multi-step process can be quite complex, making Spark less appealing.</p><p>However, Spark 3.4 introduced a promising new feature called “Spark Connect,” which simplifies Spark development.</p><p>Spark Connect introduces a decoupled client-server architecture, enabling remote connectivity to Spark clusters using the DataFrame API and unresolved logical plans as the protocol. This separation allows Spark and its open ecosystem to be leveraged from anywhere, including modern data applications, IDEs, Notebooks, and programming languages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xL7kfep3TifBNWWJtzMMaw.png" /></figure><h3>High-level Spark Connect Architecture</h3><p>Spark Connect defines a protocol for client applications to communicate with a remote Spark Server. Clients implementing this protocol can connect and make requests to remote Spark Servers, similar to how client applications connect to databases using a JDBC driver. A query like spark.table(&quot;some_table&quot;).limit(5) should simply return the result. This architecture provides an excellent developer experience.</p><ul><li>A connection is established between the Client and Spark Server.</li><li>The Client converts a DataFrame query to an unresolved logical plan, describing the operation’s intent rather than its execution.</li><li>The unresolved logical plan is encoded and sent to the Spark Server.</li><li>The Spark Server optimizes and runs the query.</li><li>The Spark Server sends the results back to the Client.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37bCV-w-GV5aHx1txiiqnQ.png" /></figure><h3>Combining Spark Connect and Spark Operator</h3><p>A skilled engineer must carefully consider resource utilization. Many real-world problems revolve around optimizing resource usage.</p><p>So, how do Spark Connect and Spark Operator manage resources?</p><p><strong>Spark Operator:</strong> When submitting a SparkApplication, Spark Operator uses the Manifest file to initialize Driver and Executor pods. After execution, these pods are terminated to free up resources, leading to better resource management.</p><p><strong>Spark Connect:</strong> A dedicated resource pool must be allocated on the server side to handle incoming client requests.</p><p><strong>Conclusion:</strong></p><p>Spark Operator offers better resource management but a more complex development process. Spark Connect provides a great developer experience but suboptimal resource management.</p><p>I propose combining both approaches:</p><ul><li>Use Spark Connect for development and integration with tools like Jupyter Notebook (for data scientists).</li><li>Employ Spark Operator for efficient resource management in production environments.</li></ul><p>This approach simplifies SparkApplications development while maintaining efficient resource utilization.</p><h3>DEPLOYMENT STEPS</h3><p>To deploy Spark Connect on Kubernetes, follow these steps:</p><ol><li>Build sparglim-server (viet1846/sparglim-server) images</li><li><a href="https://github.com/Wh1isper/sparglim">Sparglim</a> is an open-source tool on GitHub that makes it easier to deploy Spark Connect Server on Kubernetes!</li><li>However, by default, Sparglim does not have configurations integrated with Hive Metastore, MinIO, and Iceberg ⇒ We need to add some configurations related to Hive Metastore, MinIO, and Iceberg to Sparglim. For details, you can see the file <a href="https://github.com/viethqb/data-platform-notes/blob/main/spark-connect-server/sparglim/config/configer.py">https://github.com/viethqb/data-platform-notes/blob/main/spark-connect-server/sparglim/config/configer.py</a></li><li>Build sparglim-server images using Dockerfile: <a href="https://github.com/viethqb/data-platform-notes/blob/main/spark-connect-server/Dockerfile.sparglim-server">https://github.com/viethqb/data-platform-notes/blob/main/spark-connect-server/Dockerfile.sparglim-server</a></li><li>Initialize a Kubernetes cluster with Kind.</li><li>Install Nginx Ingress Controller, MinIO, Hive Metastore, and Trino on Kubernetes. (This scene is familiar. We’ve seen it somewhere before.)</li><li>Install Spark Connect Server</li><li>Test Spark Connect Server</li><li>Using Trino query Iceberg table created by Spark</li><li>Destroy the Kind cluster.</li></ol><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/spark-connect-server">https://github.com/viethqb/data-platform-notes/tree/main/spark-connect-server</a></p><h4>1. Build sparglim-server (viet1846/sparglim-server) images</h4><p>Dockerfile.sparglim-server</p><pre>FROM python:3.10.12-slim-bookworm as builder<br><br>RUN pip install build twine hatch<br>COPY . /source<br>WORKDIR /source<br>RUN python -m build<br><br>FROM viet1846/spark-lakehouse:v1<br><br>COPY --from=builder --chown=executor:executor /source/dist/*.whl /tmp/<br>RUN for f in $(echo /tmp/*.whl); do pip install --no-cache-dir $f; done<br><br>ENTRYPOINT [ &quot;tini&quot; ,&quot;--&quot;]<br>CMD [ &quot;sparglim-server&quot;, &quot;start&quot; ]<br><br># docker buildx build --platform linux/amd64,linux/arm64/v8 -t wh1isper/sparglim-server:latest -f docker/Dockerfile.sparglim-server --push .</pre><p><strong>Build sparglim-server images</strong></p><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/spark-connect-server<br>&gt; docker build -t viet1846/sparglim-server -f Dockerfile.sparglim-server .<br>&gt; docker push viet1846/sparglim-server</pre><h4>2. Initialize a Kubernetes cluster with Kind</h4><pre>&gt; cd deployment<br>&gt; kind create cluster --name dev --config ./kind-config.yaml <br>&gt; kubectl get no -owide </pre><h4>3. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino on Kubernetes</h4><p>Install Nginx Ingress Controller</p><pre>&gt; helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>&gt; helm repo update<br>&gt; helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>&gt; kubectl -n ingress-nginx get po -owide</pre><p>Install MinIO</p><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f ./minio/minio-values.yaml bitnami/minio --create-namespace --debug --version 14.6.0<br>&gt; kubectl -n minio get po<br>&gt; kubectl get no -owide<br># NAME                STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION   CONTAINER-RUNTIME<br># dev-control-plane   Ready    control-plane   3m53s   v1.30.0   172.18.0.2    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker          Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.5    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker2         Ready    &lt;none&gt;          3m12s   v1.30.0   172.18.0.3    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker3         Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.4    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15</pre><pre># Add the following lines to the end of the /etc/hosts<br># 172.18.0.4  minio.lakehouse.local</pre><p>Install Hive Metastore</p><pre># hive-metastore-postgresql<br>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install metastore-db -n metastore -f ./hive/hive-metastore-postgres-values.yaml bitnami/postgresql --create-namespace --debug --version 15.4.2<br># Hive metastore<br># docker pull rtdl/hive-metastore:3.1.2<br># kind load docker-image rtdl/hive-metastore:3.1.2 --name dev<br>&gt; helm upgrade --install hive-metastore -n metastore -f ./hive/hive-metastore-values.yaml ../../charts/hive-metastore --create-namespace --debug</pre><p><strong>Install Trino</strong></p><pre>&gt; helm repo add trino https://trinodb.github.io/charts<br>&gt; helm upgrade --install trino -n trino -f ./trino/trino-values.yaml trino/trino --create-namespace --debug --version 0.21.0<br>&gt; kubectl -n trino get po</pre><h4>4. Install Spark Connect Server</h4><pre># docker pull viet1846/sparglim-server<br># kind load docker-image viet1846/sparglim-server --name dev<br>&gt; kubectl create ns sparglim<br>&gt; kubectl create clusterrolebinding serviceaccounts-cluster-admin --clusterrole=cluster-admin --group=system:serviceaccounts<br>&gt; kubectl apply -f spark-connect-server/<br>&gt; kubectl -n sparglim logs -f deployments/sparglim-server</pre><p><strong>To change the configuration, see file:</strong> spark-connect-server/deployment.yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IBIBWiWboGIGG9vhK8bkg.png" /></figure><h4>5. Test Spark Connect Server</h4><p>demo.py</p><pre>from pyspark.sql import SparkSession<br>from datetime import datetime, date<br>from pyspark.sql import Row<br>import os<br><br>SPARK_CONNECT_SERVER = os.getenv(&quot;SPARK_CONNECT_SERVER&quot;, &quot;sc://172.25.0.2:30052&quot;)<br>spark = SparkSession.builder.remote(SPARK_CONNECT_SERVER).getOrCreate()<br><br>df = spark.createDataFrame(<br>    [<br>        Row(a=1, b=2.0, c=&quot;string1&quot;, d=date(2000, 1, 1), e=datetime(2000, 1, 1, 12, 0)),<br>        Row(a=2, b=3.0, c=&quot;string2&quot;, d=date(2000, 2, 1), e=datetime(2000, 1, 2, 12, 0)),<br>        Row(a=4, b=5.0, c=&quot;string3&quot;, d=date(2000, 3, 1), e=datetime(2000, 1, 3, 12, 0)),<br>    ]<br>)<br>df.show()<br><br>create_schema_df = spark.sql(&quot;CREATE DATABASE IF NOT EXISTS raw &quot;)<br><br>df.writeTo(&quot;raw.demo&quot;).tableProperty(<br>    &quot;write.format.default&quot;, &quot;parquet&quot;<br>).createOrReplace()</pre><pre>&gt; python3 -m venv .venv<br>&gt; source .venv/bin/activate<br>(.venv)&gt; pip3 install pyspark==3.4.1 grpcio-status pandas pyarrow<br>(.venv)&gt; export SPARK_CONNECT_SERVER=&quot;sc://172.18.0.4:30052&quot;<br>(.venv)&gt; python3 demo.py<br>(.venv)&gt; deactivate</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sl5oG05Ghvu1XoZMT6eZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4je5vrIdem43I8VvVQso8g.png" /></figure><h3>6. Using Trino query Iceberg table created by Spark</h3><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; show schemas from lakehouse;<br>trino&gt; show tables from lakehouse.raw;<br>trino&gt; select * from lakehouse.raw.demo;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Olq40blRwHa8xjizRB3K1Q.png" /></figure><h3>7. Destroy the Kind cluster</h3><pre>&gt; kind delete cluster --name dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjfC8ZiQpNUei8ajNLQhHA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=608861b262ed" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-5-2-main-components-apache-spark-with-spark-connect-server-608861b262ed">[Kubernetes Data Platform][Part 5.2][Main Components]: Apache Spark with Spark Connect Server</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 5.1][Main Components]: Apache Spark with Kubernetes Spark Operator]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-5-1-main-components-apache-spark-with-kubernetes-spark-operator-0db10a10fa7f?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/0db10a10fa7f</guid>
            <category><![CDATA[spark-on-kubernetes]]></category>
            <category><![CDATA[spark-operator]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[trinodb]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Tue, 06 Aug 2024 00:25:03 GMT</pubDate>
            <atom:updated>2024-08-23T18:28:34.716Z</atom:updated>
            <content:encoded><![CDATA[<p>To be honest, I don’t like Apache Spark, not because of its features or performance, but because of its deployment, configuration, and dependencies. There are many ways to deploy, but today I will present how to use Spark Operator, a custom resource of Kubernetes.</p><p><a href="https://github.com/kubeflow/spark-operator">The Kubernetes Operator for Apache Spark</a> aims to make specifying and running Spark applications as easy and idiomatic as running other workloads on Kubernetes. It uses Kubernetes custom resources for specifying, running, and surfacing status of Spark applications.</p><p>In simple terms, after installing Spark Operator, you will have a new resource type called SparkApplication on your Kubernetes cluster. You can then configure a manifest similar to other resource types and run kubectl to submit a Spark job.</p><p><strong>The Kubernetes Operator for Apache Spark currently supports the following list of features:</strong></p><ul><li>Supports Spark 2.3 and up.</li><li>Enables declarative application specification and management of applications through custom resources.</li><li>Automatically runs spark-submit on behalf of users for each SparkApplication eligible for submission.</li><li>Provides native <a href="https://en.wikipedia.org/wiki/Cron">cron</a> support for running scheduled applications.</li><li>Supports customization of Spark pods beyond what Spark natively is able to do through the mutating admission webhook, e.g., mounting ConfigMaps and volumes, and setting pod affinity/anti-affinity.</li><li>Supports automatic application re-submission for updated SparkApplication objects with updated specification.</li><li>Supports automatic application restart with a configurable restart policy.</li><li>Supports automatic retries of failed submissions with optional linear back-off.</li><li>Supports mounting local Hadoop configuration as a Kubernetes ConfigMap automatically via sparkctl.</li><li>Supports automatically staging local application dependencies to Google Cloud Storage (GCS) via sparkctl.</li><li>Supports collecting and exporting application-level metrics and driver/executor metrics to Prometheus.</li></ul><p><em>The architecture is as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*3J90ioUdF5iuPE_1QPOKQQ.png" /></figure><h3>DEPLOYMENT STEPS</h3><p><strong>1. Initialize a Kubernetes cluster with Kind.</strong></p><p><strong>2. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino on Kubernetes.</strong></p><ul><li>This step will be repeated in subsequent labs. Practicing multiple times will help you remember better.</li></ul><p><strong>3. Install Spark Operator and Test with the spark_pi application</strong></p><p><strong>4. Integrate Spark with Iceberg and Hive Metastore:</strong></p><ul><li>Build Base images</li><li>Build application images</li></ul><p><strong>5. Submit main_iceberg job</strong></p><p><strong>6. Using Trino query Iceberg table create by Spark</strong></p><p><strong>7. Destroy the Kind cluster.</strong></p><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/spark">https://github.com/viethqb/data-platform-notes/tree/main/spark</a></p><h4>1. Initialize a Kubernetes cluster with Kind</h4><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/spark<br>&gt; kind create cluster --name dev --config deployment/kind/kind-config.yaml<br>&gt; kubectl get no -owide </pre><h4>2. Install Nginx Ingress Controller, MinIO, Hive Metastore, Trino on Kubernetes</h4><p><strong>Install Nginx Ingress Controller</strong></p><pre>&gt; helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>&gt; helm repo update<br>&gt; helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>&gt; kubectl -n ingress-nginx get po -owide</pre><p><strong>Install MinIO</strong></p><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f deployment/minio/minio-values.yaml bitnami/minio --create-namespace --debug --version 14.6.0<br>&gt; kubectl -n minio get po<br>&gt; kubectl get no -owide<br># NAME                STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION   CONTAINER-RUNTIME<br># dev-control-plane   Ready    control-plane   3m53s   v1.30.0   172.18.0.2    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker          Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.5    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker2         Ready    &lt;none&gt;          3m12s   v1.30.0   172.18.0.3    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15<br># dev-worker3         Ready    &lt;none&gt;          3m11s   v1.30.0   172.18.0.4    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   6.9.9-arch1-1    containerd://1.7.15</pre><p>Add the following lines to the end of the /etc/hosts</p><pre>172.18.0.4 minio.lakehouse.local</pre><p>Download and Upload file <a href="https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2009-01.parquet">https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2009-01.parquet</a> to s3a://lakehouse/raw/yellow_tripdata/y=2009/m=01/yellow_tripdata_2009–01.parquet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UCqtix3eUOe0nlVI_XLewg.png" /></figure><p><strong>Install Hive Metastore</strong></p><pre># hive-metastore-postgresql<br>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install metastore-db -n metastore -f deployment/hive/hive-metastore-postgres-values.yaml bitnami/postgresql --create-namespace --debug --version 15.4.2<br><br># Hive metastore<br># docker pull rtdl/hive-metastore:3.1.2<br># kind load docker-image rtdl/hive-metastore:3.1.2 --name dev<br>&gt; helm upgrade --install hive-metastore -n metastore -f deployment/hive/hive-metastore-values.yaml ../charts/hive-metastore --create-namespace --debug</pre><p><strong>Install Trino</strong></p><pre>&gt; helm repo add trino https://trinodb.github.io/charts<br>&gt; helm upgrade --install trino -n trino -f deployment/trino/trino-values.yaml trino/trino --create-namespace --debug --version 0.21.0<br><br>&gt; kubectl -n trino get po</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYLngQXuvcm6genR3S-pTA.png" /></figure><h4>3. Install Spark Operator and Test with the spark_pi application</h4><p><strong>Install Spark Operator</strong></p><pre>&gt; helm repo add spark-operator https://kubeflow.github.io/spark-operator <br>&gt; helm repo update<br>&gt; helm upgrade --install spark-operator spark-operator/spark-operator --namespace spark-operator --set webhook.enable=true --set image.tag=v1beta2-1.4.6-3.5.0 --create-namespace --debug --version 1.3.2 <br>&gt; kubectl -n spark-operator get po</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmXCKnqyt2Wo8rNWHuVA0Q.png" /></figure><p><strong>Test with the spark_pi application</strong></p><p>spark_pi.yaml</p><pre>apiVersion: &quot;sparkoperator.k8s.io/v1beta2&quot;<br>kind: SparkApplication<br>metadata:<br>  # name: pyspark-pi-{{ ts_nodash|lower }}-{{ task_instance.try_number }}<br>  name: pyspark-pi<br>  namespace: spark-operator<br>spec:<br>  type: Python<br>  pythonVersion: &quot;3&quot;<br>  mode: cluster<br>  image: &quot;viet1846/spark-py:v3.5.1&quot;<br>  imagePullPolicy: Always<br>  mainApplicationFile: local:///opt/spark/examples/src/main/python/pi.py<br>  sparkVersion: &quot;3.5.1&quot;<br>  restartPolicy:<br>    type: OnFailure<br>    onFailureRetries: 3<br>    onFailureRetryInterval: 10<br>    onSubmissionFailureRetries: 5<br>    onSubmissionFailureRetryInterval: 20<br>  driver:<br>    cores: 1<br>    coreLimit: &quot;1200m&quot;<br>    memory: &quot;512m&quot;<br>    labels:<br>      version: 3.5.1<br>    serviceAccount: spark-operator-spark<br>  executor:<br>    cores: 1<br>    instances: 1<br>    memory: &quot;512m&quot;<br>    labels:<br>      version: 3.5.1</pre><p>Spark submit job</p><pre># docker pull viet1846/spark-py:v3.5.1<br># kind load docker-image viet1846/spark-py:v3.5.1 --name dev<br>&gt; kubectl apply -f jobs/spark_pi.yaml<br>&gt; kubectl -n spark-operator get po -w<br>&gt; kubectl -n spark-operator logs -f pyspark-pi-driver</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xNHsZS9Unt1hVJM-EV3IKQ.png" /></figure><p>Get sparkapplications resource:</p><pre>&gt; kubectl -n spark-operator get sparkapplications<br>&gt; kubectl -n spark-operator describe sparkapplications pyspark-pi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T1LG8JsTZdNUiznRAGtLpQ.png" /></figure><h4>4. Integrate Spark with Iceberg and Hive Metastore</h4><p>Environment config: src/config.py</p><pre>import os<br><br>AWS_ACCESS_KEY_ID = os.getenv(&quot;AWS_ACCESS_KEY_ID&quot;, &quot;admin&quot;)<br>AWS_SECRET_ACCESS_KEY = os.getenv(&quot;AWS_SECRET_ACCESS_KEY&quot;, &quot;password&quot;)<br>S3_ENDPOINT = os.getenv(&quot;S3_ENDPOINT&quot;, &quot;minio.minio.svc.cluster.local:9000&quot;)<br>S3_SSL_ENABLE = os.getenv(&quot;S3_SSL_ENABLE&quot;, &quot;false&quot;)<br>S3_PATH_STYLE_ACCESS = os.getenv(&quot;S3_PATH_STYLE_ACCESS&quot;, &quot;true&quot;)<br>S3_ATTEMPTS_MAXIMUM = os.getenv(&quot;S3_ATTEMPTS_MAXIMUM&quot;, &quot;1&quot;)<br>S3_CONNECTION_ESTABLISH_TIMEOUT = os.getenv(&quot;S3_CONNECTION_ESTABLISH_TIMEOUT&quot;, &quot;5000&quot;)<br>S3_CONNECTION_TIMEOUT = os.getenv(&quot;S3_CONNECTION_TIMEOUT&quot;, &quot;10000&quot;)<br><br>S3_WAREHOUSE = os.getenv(&quot;S3_WAREHOUSE&quot;, &quot;s3a://lakehouse/&quot;)<br>S3_HTTP_ENDPOINT = (<br>    f&quot;https://{S3_ENDPOINT}&quot; if S3_SSL_ENABLE == &quot;true&quot; else f&quot;http://{S3_ENDPOINT}&quot;<br>)<br>METASTORE_URI = os.getenv(<br>    &quot;METASTORE_URI&quot;, &quot;thrift://hive-metastore.metastore.svc.cluster.local:9083&quot;<br>)</pre><p>Spark config with Hive Metastore, Minio and Iceberg: src/utils.py</p><pre>import logging<br>from pyspark import SparkConf<br>from pyspark import SparkContext<br>from pyspark.sql import SparkSession<br>from config import *<br><br><br>def load_config(spark_context: SparkContext):<br>    spark_context._jsc.hadoopConfiguration().set(&quot;fs.s3a.access.key&quot;, AWS_ACCESS_KEY_ID)<br>    spark_context._jsc.hadoopConfiguration().set(<br>        &quot;fs.s3a.secret.key&quot;, AWS_SECRET_ACCESS_KEY<br>    )<br>    spark_context._jsc.hadoopConfiguration().set(&quot;fs.s3a.endpoint&quot;, S3_ENDPOINT)<br>    spark_context._jsc.hadoopConfiguration().set(<br>        &quot;fs.s3a.connection.ssl.enabled&quot;, S3_SSL_ENABLE<br>    )<br>    spark_context._jsc.hadoopConfiguration().set(<br>        &quot;fs.s3a.path.style.access&quot;, S3_PATH_STYLE_ACCESS<br>    )<br>    spark_context._jsc.hadoopConfiguration().set(<br>        &quot;fs.s3a.attempts.maximum&quot;, S3_ATTEMPTS_MAXIMUM<br>    )<br>    spark_context._jsc.hadoopConfiguration().set(<br>        &quot;fs.s3a.connection.establish.timeout&quot;, S3_CONNECTION_ESTABLISH_TIMEOUT<br>    )<br>    spark_context._jsc.hadoopConfiguration().set(<br>        &quot;fs.s3a.connection.timeout&quot;, S3_CONNECTION_TIMEOUT<br>    )<br><br><br>def get_spark(<br>    job_name,<br>):<br>    logging.basicConfig(<br>        level=logging.INFO,<br>        format=&quot;%(asctime)s - %(name)s - %(levelname)s - %(message)s&quot;,<br>    )<br>    logger = logging.getLogger(job_name)<br><br>    # adding iceberg configs<br>    conf = (<br>        SparkConf()<br>        .set(<br>            &quot;spark.sql.extensions&quot;,<br>            &quot;org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions&quot;,<br>        )  # Use Iceberg with Spark<br>        .set(&quot;spark.sql.catalog.lakehouse&quot;, &quot;org.apache.iceberg.spark.SparkCatalog&quot;)<br>        .set(<br>            &quot;spark.sql.catalog.lakehouse.io-impl&quot;, &quot;org.apache.iceberg.aws.s3.S3FileIO&quot;<br>        )<br>        .set(&quot;spark.sql.catalog.lakehouse.warehouse&quot;, S3_WAREHOUSE)<br>        .set(&quot;spark.sql.catalog.lakehouse.s3.path-style-access&quot;, S3_PATH_STYLE_ACCESS)<br>        .set(<br>            &quot;spark.sql.catalog.lakehouse.s3.endpoint&quot;,<br>            S3_HTTP_ENDPOINT,<br>        )<br>        .set(&quot;spark.sql.defaultCatalog&quot;, &quot;lakehouse&quot;)  # Name of the Iceberg catalog<br>        .set(&quot;spark.sql.catalogImplementation&quot;, &quot;in-memory&quot;)<br>        .set(&quot;spark.sql.catalog.lakehouse.type&quot;, &quot;hive&quot;)  # Iceberg catalog type<br>        .set(&quot;spark.sql.catalog.lakehouse.uri&quot;, METASTORE_URI)<br>        .set(&quot;spark.executor.heartbeatInterval&quot;, &quot;300000&quot;)<br>        .set(&quot;spark.network.timeout&quot;, &quot;400000&quot;)<br>    )<br><br>    spark = SparkSession.builder.config(conf=conf).getOrCreate()<br><br>    # Disable below line to see INFO logs<br>    spark.sparkContext.setLogLevel(&quot;ERROR&quot;)<br>    load_config(spark.sparkContext)<br><br>    return spark, logger</pre><p>Demo code: etl/main_iceberg.py</p><pre>import os<br>from utils import get_spark<br><br>spark, logger = get_spark(job_name=&quot;main_spark&quot;)<br><br>DATA_PATH = os.getenv(&quot;DATA_PATH&quot;, &quot;s3a://lakehouse/raw/yellow_tripdata/&quot;)<br>df = spark.read.option(&quot;mergeSchema&quot;, &quot;true&quot;).parquet(DATA_PATH)<br><br>create_schema_df = spark.sql(&quot;CREATE DATABASE IF NOT EXISTS raw &quot;)<br>create_schema_df.show()<br># Create Iceberg table &quot;nyc.taxis_large&quot; from RDD<br># df.write.mode(&quot;overwrite&quot;).saveAsTable(&quot;raw.taxis_spark&quot;)<br>df.writeTo(&quot;raw.taxis_spark&quot;).tableProperty(<br>    &quot;write.format.default&quot;, &quot;parquet&quot;<br>).partitionedBy(&quot;y&quot;, &quot;m&quot;).createOrReplace()<br># Query table row count<br>count_df = spark.sql(&quot;SELECT COUNT(*) AS cnt FROM raw.taxis_spark&quot;)<br>total_rows_count = count_df.first().cnt<br>logger.info(f&quot;Total Rows for NYC Taxi Data: {total_rows_count}&quot;)</pre><p>Base image (viet1846/spark-iceberg:3.4.1) Dockerfile: Dockerfile.spark-iceberg</p><pre>FROM apache/spark:3.4.1-scala2.12-java11-python3-ubuntu<br><br>USER root<br><br>ENV SPARK_VERSION_SHORT=3.4<br>ENV SPARK_VERSION=3.4.2<br>ENV AWS_SDK_VERSION=1.12.262<br>ENV HADOOP_AWS_VERSION=3.3.4<br><br># Configure SPARK<br>RUN apt-get update -y &amp;&amp; apt-get install -y curl wget<br>RUN curl https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-aws/${HADOOP_AWS_VERSION}/hadoop-aws-${HADOOP_AWS_VERSION}.jar -o ${SPARK_HOME}/jars/hadoop-aws-${HADOOP_AWS_VERSION}.jar<br>RUN curl https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-bundle/${AWS_SDK_VERSION}/aws-java-sdk-bundle-${AWS_SDK_VERSION}.jar -o ${SPARK_HOME}/jars/aws-java-sdk-bundle-${AWS_SDK_VERSION}.jar<br>RUN curl https://repo1.maven.org/maven2/org/apache/spark/spark-hadoop-cloud_2.12/${SPARK_VERSION}/spark-hadoop-cloud_2.12-3.3.0.jar -o ${SPARK_HOME}/jars/spark-hadoop-cloud_2.12-${SPARK_VERSION}.jar<br><br># Configure ICEBERG<br>ENV ICEBERG_VERSION=1.5.0<br>ENV AWS_SDK_BUNDLE_VERSION=2.20.18<br><br>RUN curl https://repo1.maven.org/maven2/org/apache/iceberg/iceberg-spark-runtime-${SPARK_VERSION_SHORT}_2.12/${ICEBERG_VERSION}/iceberg-spark-runtime-${SPARK_VERSION_SHORT}_2.12-${ICEBERG_VERSION}.jar -o ${SPARK_HOME}/jars/iceberg-spark-runtime-${SPARK_VERSION_SHORT}_2.12-${ICEBERG_VERSION}.jar<br>RUN curl https://repo1.maven.org/maven2/software/amazon/awssdk/bundle/${AWS_SDK_BUNDLE_VERSION}/bundle-${AWS_SDK_BUNDLE_VERSION}.jar -Lo /opt/spark/jars/aws-bundle-${AWS_SDK_BUNDLE_VERSION}.jar<br>RUN curl https://repo1.maven.org/maven2/software/amazon/awssdk/url-connection-client/${AWS_SDK_BUNDLE_VERSION}/url-connection-client-${AWS_SDK_BUNDLE_VERSION}.jar -Lo /opt/spark/jars/url-connection-client-${AWS_SDK_BUNDLE_VERSION}.jar<br><br># Configure PYTHON<br>ENV PYTHONPATH=$SPARK_HOME/python:$SPARK_HOME/python/lib/py4j-0.10.9.7-src.zip:$PYTHONPATH</pre><p>Application image (viet1846/spark-lakehouse:v1) Dockerfile: Dockerfile</p><pre>FROM viet1846/spark-iceberg:3.4.1<br><br>ENV  PYTHONPATH=/app:$PYTHONPATH<br><br><br>WORKDIR /app<br>COPY src/ /app/</pre><p>Spark Iceberg demo job: jobs/main_iceberg.yaml</p><pre>---<br>apiVersion: &quot;sparkoperator.k8s.io/v1beta2&quot;<br>kind: SparkApplication<br>metadata:<br>  name: spark-iceberg<br>  namespace: spark-operator<br>spec:<br>  type: Python<br>  pythonVersion: &quot;3&quot;<br>  mode: cluster<br>  image: &quot;viet1846/spark-lakehouse:v1&quot;<br>  imagePullPolicy: Always<br>  mainApplicationFile: local:///app/etl/main_iceberg.py<br>  sparkVersion: &quot;3.4.1&quot;<br>  restartPolicy:<br>    type: OnFailure<br>    onFailureRetries: 3<br>    onFailureRetryInterval: 10<br>    onSubmissionFailureRetries: 5<br>    onSubmissionFailureRetryInterval: 20<br>  driver:<br>    cores: 1<br>    memory: &quot;1024m&quot;<br>    labels:<br>      version: 3.4.1<br>    serviceAccount: spark-operator-spark<br>    env:<br>      - name: AWS_REGION<br>        value: us-east-1<br>      - name: AWS_ACCESS_KEY_ID<br>        value: admin<br>      - name: AWS_SECRET_ACCESS_KEY<br>        value: password<br>      - name: S3_ENDPOINT<br>        value: minio.minio.svc.cluster.local:9000<br>      - name: S3_SSL_ENABLE<br>        value: &quot;false&quot;<br>      - name: S3_PATH_STYLE_ACCESS<br>        value: &quot;true&quot;<br>      - name: S3_WAREHOUSE<br>        value: &quot;s3a://lakehouse/&quot;<br>      - name: METASTORE_URI<br>        value: &quot;thrift://hive-metastore.metastore.svc.cluster.local:9083&quot;<br>      - name: DATA_PATH<br>        value: &quot;s3a://lakehouse/raw/yellow_tripdata/&quot;<br>        <br>  executor:<br>    cores: 1<br>    instances: 3<br>    memory: &quot;2048m&quot;<br>    labels:<br>      version: 3.4.1<br>    env:<br>      - name: AWS_REGION<br>        value: us-east-1<br>      - name: AWS_ACCESS_KEY_ID<br>        value: admin<br>      - name: AWS_SECRET_ACCESS_KEY<br>        value: password<br>      - name: S3_ENDPOINT<br>        value: minio.minio.svc.cluster.local:9000<br>      - name: S3_SSL_ENABLE<br>        value: &quot;false&quot;<br>      - name: S3_PATH_STYLE_ACCESS<br>        value: &quot;true&quot;<br>      - name: S3_WAREHOUSE<br>        value: &quot;s3a://lakehouse/&quot;<br>      - name: METASTORE_URI<br>        value: &quot;thrift://hive-metastore.metastore.svc.cluster.local:9083&quot;<br>      - name: DATA_PATH<br>        value: &quot;s3a://lakehouse/raw/yellow_tripdata/&quot;</pre><p>Build Base images</p><pre>&gt; docker build -t viet1846/spark-iceberg:3.4.1 -f Dockerfile.spark-iceberg .<br>&gt; docker push viet1846/spark-iceberg:3.4.1</pre><p>Build application images</p><pre>&gt; docker build -t viet1846/spark-lakehouse:v1 -f Dockerfile .<br>&gt; docker push viet1846/spark-lakehouse:v1</pre><h4>5. Submit Spark Iceberg demo job</h4><pre>&gt; docker pull viet1846/spark-lakehouse:v1<br>&gt; kind load docker-image viet1846/spark-lakehouse:v1 --name dev<br>&gt; kubectl apply -f jobs/main_iceberg.yaml<br>&gt; kubectl -n spark-operator logs -f spark-iceberg-driver</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94iWt1OfWxYXc57PcGroqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G33aygr_z7MFe5V5OPDq5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rYcwlH5jtX0ZmI-Ce2xV4A.png" /></figure><h4>6. Using Trino query Iceberg table create by Spark</h4><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; show schemas from lakehouse;<br>trino&gt; show tables from lakehouse.raw;<br>trino&gt; select * from lakehouse.raw.taxis_spark limit 10;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXud5fgJBvQGDFquN3NYWg.png" /></figure><h4>7. Destroy the Kind cluster</h4><pre>&gt; kind delete cluster --name dev </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0db10a10fa7f" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-5-1-main-components-apache-spark-with-kubernetes-spark-operator-0db10a10fa7f">[Kubernetes Data Platform][Part 5.1][Main Components]: Apache Spark with Kubernetes Spark Operator</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 4][Main Components]: Install Hive Metastore, Trino on Kubernetes]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-4-main-components-install-hive-metastore-trino-on-kubernetes-788e34bc2126?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/788e34bc2126</guid>
            <category><![CDATA[apache-iceberg]]></category>
            <category><![CDATA[prestodb]]></category>
            <category><![CDATA[trinodb]]></category>
            <category><![CDATA[hive-metastore]]></category>
            <category><![CDATA[minio]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Mon, 05 Aug 2024 00:07:11 GMT</pubDate>
            <atom:updated>2024-08-23T18:28:45.480Z</atom:updated>
            <content:encoded><![CDATA[<p>As we know, a Data Platform consists of four main components (Review Part 1):</p><ul><li><strong>Storage:</strong> We will use MinIO. In Part 3, we learned how to deploy a multi-node, multi-disk MinIO cluster. In this article, we will deploy MinIO on Kubernetes to save time.</li><li><strong>Metastore:</strong> We will use Hive Metastore. In this article, we will also install it to run on Kubernetes.</li><li><strong>Table Format:</strong> We will choose Apache Iceberg.</li><li><strong>Processing Engine:</strong> We will choose Trino.</li></ul><p>In this article, we will deploy the data stack on a Kubernetes cluster created using Kind (Kubernetes in Docker).</p><p><strong>Note:</strong> We are using Kind for the dev environment. For production, we should choose one of the methods presented in Part 2.1 to Part 2.4.</p><h3><strong>New Terms:</strong></h3><p><a href="https://hive.apache.org/"><strong>Hive Metastore</strong></a><strong>:</strong> This is a familiar tool if you have ever worked with the Hadoop Ecosystem. The Hive Metastore (HMS) is a central repository of metadata for Hive tables and partitions in a relational database, and provides clients (including Hive, Impala, and Spark) access to this information using the metastore service API. It has become a building block for data lakes that utilize the diverse world of open-source software, such as Apache Spark and Presto. In fact, a whole ecosystem of tools, open-source and otherwise, are built around the Hive Metastore, some of which this diagram illustrates.</p><p><a href="https://iceberg.apache.org/"><strong>Apache Iceberg</strong></a>: Iceberg is a high-performance format for large analytic tables. Iceberg brings the reliability and simplicity of SQL tables to big data, while making it possible for engines like Spark, Trino, Flink, Presto, Hive, and Impala to safely work with the same tables at the same time.</p><p><a href="https://trino.io/"><strong>Trino</strong></a>: Trino (formerly known as Presto) is an open-source distributed SQL query engine designed to query large datasets distributed across one or more heterogeneous data sources.</p><p><strong>Key features of Trino include:</strong></p><ul><li><strong>Standard SQL support:</strong> Trino adheres to the ANSI SQL standard, allowing you to use familiar SQL queries to query your data.</li><li><strong>Fast query performance:</strong> Trino utilizes a distributed architecture and advanced query processing techniques to deliver fast query performance, even for large datasets.</li><li><strong>High scalability:</strong> Trino can be scaled horizontally to handle any amount of data.</li><li><strong>Support for multiple data sources:</strong> Trino can query data from a variety of sources, including data warehouses, data lakes, relational databases, cloud storage systems, and more.</li><li><strong>Ease of use:</strong> Trino is easy to install, configure, and use.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jv7amOjemIlafpjqLUuLEA.png" /></figure><h3>DEPLOYMENT STEPS</h3><p><strong>1. Initialize a Kubernetes cluster with Kind.</strong></p><p><strong>2. Install Nginx Ingress Controller.</strong></p><p><strong>3. Install MinIO</strong></p><p><strong>4. Install data sources:</strong></p><ul><li>Install MySQL on Kubernetes.</li><li>Install PostgreSQL on Kubernetes.</li><li>Download Parquet file: <a href="https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2009-01.parquet">https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2009-01.parquet</a> ⇒ Upload the Parquet file using the Minio Console.</li></ul><p><strong>5. Install Hive Metastore:</strong></p><ul><li>Install PostgreSQL.</li><li>Install Hive Metastore.</li></ul><p><strong>6. Install Trino and test some features:</strong></p><ul><li>Read a Parquet file on MinIO.</li><li>Read a table on MySQL and PostgreSQL.</li><li>Join 2 tables in 2 databases</li><li>Write to MinIO in Iceberg format.</li><li>Trino web UI</li></ul><p><strong>7. Destroy the Kind cluster.</strong></p><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/trino">https://github.com/viethqb/data-platform-notes/tree/main/trino</a></p><h4>1. Initialize a Kubernetes cluster with Kind</h4><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/trino<br>&gt; kind create cluster --name dev --config deployment/kind/kind-config.yaml<br>&gt; kubectl get no -owide </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FcP5UnHvfCR7kr35cTvuHQ.png" /><figcaption>Kind Kubernetes Cluster</figcaption></figure><h4>2. Install Nginx Ingress Controller</h4><pre># Install ingress nginx<br>root@master-1:~# helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>root@master-1:~# helm repo update<br>root@master-1:~# helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>root@master-1:~# kubectl -n ingress-nginx get all<br>root@master-1:~# kubectl get IngressClass</pre><h4>3. Install MinIO on Kubernetes</h4><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f deployment/minio/minio-values.yaml bitnami/minio --create-namespace --debug --version 14.6.0<br>&gt; kubectl -n minio get po -owide<br>&gt; kubectl -n minio get ing<br>&gt; kubectl get no -owide<br>&gt; sudo vim /etc/hosts<br># Add the following lines to the end of the /etc/hosts<br># 172.18.0.5  minio.lakehouse.local</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QY5FLFaHKp6E8jv5WEJ4Eg.png" /></figure><p>Access Minio at <a href="http://minio.lakehouse.local/">http://minio.lakehouse.local/</a> in your web browser with user: admin &amp; password: password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7JU4zbYg1V2F1B6XrSVepQ.png" /></figure><h4>4. Install data sources</h4><p><strong>Install MySQL on Kubernetes</strong></p><pre>&gt; kubectl apply -f deployment/mysql/namespace.yaml<br>&gt; kubectl apply -f deployment/mysql/deployment.yaml<br>&gt; kubectl apply -f deployment/mysql/serrvice.yaml<br># user: root / password: debezium</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yf51i7zqChgF5Svte4lmAw.png" /></figure><p><strong>Check mysql data</strong></p><pre>#check mysql data<br>&gt; kubectl -n data-source exec -it deployments/mysql bash<br>bash-4.4# mysql -uroot -P3306 -hmysql.data-source -p<br>mysql&gt; show databases;<br>mysql&gt; show tables in inventory;<br>mysql&gt; select * from inventory.customers;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKqXexvg9jKYTdI-YbxrTQ.png" /></figure><p><strong>Install PostgreSQL on Kubernetes</strong></p><pre>&gt; kubectl apply -f deployment/postgres/postgres.yaml<br># user/password: data_engineer/password<br># psql -h postgres.data-source -p 5432 -U data_engineer -d data_engineer<br><br>&gt; kubectl apply -f deployment/postgres/postgresql-client.yml<br>&gt; kubectl -n data-source exec -it postgresql-client sh<br>~ $ psql -h postgres.data-source -p 5432 -U data_engineer -d data_engineer<br>data_engineer=# \dt inventory.*<br>data_engineer=# select * from inventory.customers;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nO6R6umxw8DfV3qf2POpWQ.png" /></figure><p><strong>Upload the Parquet file using the Minio Console</strong></p><p>Access Minio at <a href="http://minio.lakehouse.local/browser/lakehouse">http://minio.lakehouse.local/browser/lakehouse</a> in your web browser =&gt; create new path: raw/yellow_tripdata/y=2009/m=01 =&gt; Upload file: <strong>yellow_tripdata_2009–01.parquet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V2VusCeWqm0OJL1lfmHzQQ.png" /></figure><h4>5. Install Hive Metastore on Kubernetes</h4><p><strong>Install hive-metastore-postgresql</strong></p><pre>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install metastore-db -n metastore -f deployment/hive/hive-metastore-postgres-values.yaml bitnami/postgresql --create-namespace --debug --version 15.4.2<br>&gt; kubectl -n metastore get all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDiY3oGYhK4ObgRAu098kQ.png" /></figure><p><strong>Install Hive metastore</strong></p><pre># docker pull rtdl/hive-metastore:3.1.2<br># kind load docker-image rtdl/hive-metastore:3.1.2 --name dev<br>&gt; helm upgrade --install hive-metastore -n metastore -f deployment/hive/hive-metastore-values.yaml ../charts/hive-metastore --create-namespace --debug<br>&gt; kubectl -n metastore get all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOmykRArqjylE8uWGf1fRQ.png" /></figure><h4>6. Install Trino on Kubernetes</h4><p><strong>trino-values.yaml</strong></p><pre>additionalCatalogs:<br>  lakehouse: |<br>    connector.name=iceberg<br>    hive.metastore.uri=thrift://hive-metastore.metastore.svc.cluster.local:9083<br>    hive.s3.path-style-access=true<br>    hive.s3.endpoint=http://minio.minio.svc.cluster.local:9000<br>    hive.s3.aws-access-key=admin<br>    hive.s3.aws-secret-key=password<br>    iceberg.register-table-procedure.enabled=true<br>    iceberg.unique-table-location=true<br>    iceberg.hive-catalog-name=minio<br>  minio: |<br>    connector.name=hive<br>    hive.metastore.uri=thrift://hive-metastore.metastore.svc.cluster.local:9083<br>    hive.s3.path-style-access=true<br>    hive.s3.endpoint=http://minio.minio.svc.cluster.local:9000<br>    hive.s3.aws-access-key=admin<br>    hive.s3.aws-secret-key=password<br>    hive.metastore.thrift.client.connect-timeout=3m<br>    hive.metastore.thrift.client.read-timeout=3m<br>    hive.s3.connect-timeout=3m<br>    hive.s3.socket-timeout=3m<br>    hive.non-managed-table-writes-enabled=true<br>    hive.storage-format=ORC<br>    hive.partition-projection-enabled=true<br>  postgresql: |<br>    connector.name=postgresql<br>    connection-url=jdbc:postgresql://postgres.data-source.svc.cluster.local:5432/data_engineer<br>    connection-user=data_engineer<br>    connection-password=password<br>  mysql: |<br>    connector.name=mysql<br>    connection-url=jdbc:mysql://mysql.data-source.svc.cluster.local:3306?zeroDateTimeBehavior=convertToNull<br>    connection-user=root<br>    connection-password=debezium<br>    case-insensitive-name-matching=true</pre><p><strong>Install Trino on Kubernetes</strong></p><blockquote>Trino has various configurations. To view all the configurations of the Helm chart, use the command: <strong>helm show values trino/trino &gt; trino-values.yaml</strong></blockquote><blockquote>Then, modify the trino-values.yaml file to suit your specific needs.</blockquote><pre>&gt; helm repo add trino https://trinodb.github.io/charts<br>&gt; helm repo update<br>&gt; helm upgrade --install trino -n trino -f deployment/trino/trino-values.yaml trino/trino --create-namespace --debug --version 0.21.0</pre><p><strong>Read a Parquet file on MinIO</strong></p><p>Create table using <a href="https://trino.io/docs/current/connector/hive.html">Hive connector</a>:</p><pre>&gt; kubectl -n trino exec -it deployments/trino-coordinator trino<br>trino&gt; CREATE SCHEMA lakehouse.raw WITH (location = &#39;s3a://lakehouse/raw/&#39;);<br>trino&gt; CREATE TABLE IF NOT EXISTS minio.raw.yellow_tripdata (<br> vendor_name varchar,<br> Trip_Pickup_DateTime varchar,<br> Trip_Dropoff_DateTime varchar,<br> Passenger_Count bigint,<br> Trip_Distance double,<br> Start_Lon double,<br> Start_Lat double,<br> Rate_Code double,<br> store_and_forward double,<br> End_Lon double,<br> End_Lat double,<br> Payment_Type Varchar,<br> Fare_Amt double,<br> surcharge double,<br> mta_tax double,<br> Tip_Amt double,<br> Tolls_Amt double,<br> Total_Amt double,<br> y varchar,<br> m varchar<br>)<br>WITH<br>(<br>    format = &#39;PARQUET&#39;,<br>    external_location = &#39;s3a://lakehouse/raw/yellow_tripdata&#39;,<br>    partitioned_by = ARRAY[ &#39;y&#39;, &#39;m&#39; ]<br>);<br><br>trino&gt; CALL minio.system.sync_partition_metadata(&#39;raw&#39;, &#39;yellow_tripdata&#39;, &#39;FULL&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m_3kKdTk-GCW5f4yBVpNsA.png" /></figure><p><strong>Read Hive table</strong></p><pre>trino&gt; select * from minio.raw.yellow_tripdata limit 10;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uY9z7m7Hq3SrlBM9oro8VA.png" /></figure><p><strong>Read a table on MySQL</strong></p><p>Show infomations mysql catalogs</p><pre>trino&gt; show catalogs;<br>trino&gt; show schemas from mysql;<br>trino&gt; show tables from mysql.inventory;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZ43URg9rWChfyHlXflx9A.png" /></figure><p>Read data from mysql catalog</p><pre>trino&gt; select * from mysql.inventory.customers;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwpGMM-8NvF4GJw13dtL5A.png" /></figure><p><strong>Read a table on PostgreSQL</strong></p><pre>trino&gt; show schemas from postgresql;<br>trino&gt; show tables from postgresql.inventory;<br>trino&gt; select * from postgresql.inventory.orders;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VV0YDM359ujVOACe9tZ8ig.png" /></figure><p><strong>Join 2 tables in 2 databases</strong></p><pre>trino&gt; select t1.*, t2.name, t2.description, t2.weight from postgresql.inventory.orders t1<br>       left join mysql.inventory.products t2 on t1.product_id = t2.id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJbNzE8Lc9xdff7Zsw9F9w.png" /></figure><p><strong>Write to MinIO in Iceberg format</strong></p><p>Postgres + Mysql to Iceberg</p><pre>trino&gt; create table lakehouse.raw.join_table as<br>       select t1.*, t2.name, t2.description, t2.weight from postgresql.inventory.orders t1<br>       left join mysql.inventory.products t2 on t1.product_id = t2.id;<br>       <br>trino&gt; select * from lakehouse.raw.join_table;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1ZtiCMxJ7ZzUDnZ8EFrRQ.png" /></figure><p>join_table on MinIO</p><pre>trino&gt; create table lakehouse.raw.join_table as<br> select t1.*, t2.name, t2.description, t2.weight from postgresql.inventory.orders t1<br> left join mysql.inventory.products t2 on t1.product_id = t2.id;<br> <br>trino&gt; select * from lakehouse.raw.join_table;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZPE5wVnSqspvD8JuNle4ng.png" /></figure><p><strong>Parquet to Iceberg</strong></p><p>Create Iceberg table</p><pre>trino&gt; CREATE TABLE IF NOT EXISTS lakehouse.raw.yellow_tripdata_trino_iceberg (<br>        vendor_name varchar,<br>        Trip_Pickup_DateTime varchar,<br>        Trip_Dropoff_DateTime varchar,<br>        Passenger_Count bigint,<br>        Trip_Distance double,<br>        Start_Lon double,<br>        Start_Lat double,<br>        Rate_Code double,<br>        store_and_forward double,<br>        End_Lon double,<br>        End_Lat double,<br>        Payment_Type Varchar,<br>        Fare_Amt double,<br>        surcharge double,<br>        mta_tax double,<br>        Tip_Amt double,<br>        Tolls_Amt double,<br>        Total_Amt double,<br>        y varchar,<br>        m varchar<br>       )<br>       WITH<br>       (<br>           format = &#39;PARQUET&#39;,<br>           format_version = 2,<br>           partitioning = ARRAY[ &#39;y&#39;, &#39;m&#39; ]<br>       );</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Pq0UfLfUAWj6vCFvEad1A.png" /></figure><p>Insert data to Iceberg table</p><pre>trino&gt; insert into lakehouse.raw.yellow_tripdata_trino_iceberg<br>       select * from lakehouse.raw.yellow_tripdata;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9OzOorLj7eJdxVxovsG9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eA8HzvfVfHK2GlN1HhHPsw.png" /></figure><p><a href="https://trino.io/docs/current/admin/web-interface.html"><strong>Trino Web UI</strong></a></p><p>Trino provides a web-based user interface (UI) for monitoring a Trino cluster and managing queries. The Web UI is accessible on the coordinator via HTTP or HTTPS, using the corresponding port number specified in the coordinator Config properties. It can be configured with Web UI properties.</p><pre>&gt; kubectl -n trino port-forward services/trino 9000:8080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qFN_C93tVVKp7jgLQClWDA.png" /></figure><h4>7. Destroy the Kind cluster.</h4><pre>kind delete cluster --name dev </pre><h3>Conclusion</h3><p>In this article, we have successfully deployed Trino and integrated it with Hive Metastore, MinIO, MySQL, and PostgreSQL.</p><p>We have demonstrated Trino’s capabilities by:</p><ul><li>Reading a Parquet file from MinIO</li><li>Reading a table from PostgreSQL</li><li>Joining two tables across different databases: one in MySQL, the other in PostgreSQL</li><li>Writing data to MinIO in Iceberg format</li></ul><p>I believe you now have a good understanding of how Trino works.</p><p>When implementing Trino in a production environment, you may need to adjust configurations to optimize performance based on your specific workload and available resources.</p><p>My latest data platform also leverages Trino as the core processing engine. Combining Trino with dbt and Airflow creates a powerful ETL solution. I will delve deeper into this architecture in upcoming articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=788e34bc2126" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-4-main-components-install-hive-metastore-trino-on-kubernetes-788e34bc2126">[Kubernetes Data Platform][Part 4][Main Components]: Install Hive Metastore, Trino on Kubernetes</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 3][Main Components]: Install Distributed MinIO Cluster]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-3-main-components-install-distributed-minio-cluster-ceca1d9f81e0?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ceca1d9f81e0</guid>
            <category><![CDATA[data-platforms]]></category>
            <category><![CDATA[minio]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[data-lakehouse]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Sat, 03 Aug 2024 23:24:00 GMT</pubDate>
            <atom:updated>2024-08-25T17:37:46.579Z</atom:updated>
            <content:encoded><![CDATA[<p>MinIO is a high-performance object storage system released under the GNU Affero General Public License v3.0. It is API-compatible with the Amazon S3 cloud storage service. In simpler terms, MinIO is an open-source version of Amazon S3, so any technology that integrates with S3 can also integrate with MinIO. We use MinIO to replace HDFS.</p><p>In previous sections, we deployed MinIO on Kubernetes to test the functionality of the k8s cluster. However, this method is only suitable for testing and cannot be applied to the production environment. In this article, I will present how to deploy a MinIO cluster with multiple nodes and each node will have multiple disks attached.</p><h3><strong>Deployment model</strong></h3><ul><li>There are 4 MinIO nodes, each with 4 disks attached, and one node acting as a load balancer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*71VQSd89sZDpqzCr4xo_uw.png" /><figcaption>MinIO Multiple nodes &amp; Disks Cluster</figcaption></figure><h3>DEPLOYMENT STEPS</h3><p><strong>1. Provision virtual machines using Vagrant and VirtualBox:</strong></p><ul><li>Including 4 servers for MinIO and 1 load balancer server</li><li>loadbalancer (IP 172.16.16.100)</li><li>minio1 — minio4 (IP 172.16.16.101–172.16.16.104)</li><li>Modify line 40 of the Vagrantfile to change the storage location of the disks attached to the virtual machine. (Details can be found in the Vagrantfile)</li></ul><p><strong>2. Create mount points and mount the corresponding disks to the mount points.</strong></p><p><strong>3. Copy the docker-compose file corresponding to each node and start the minio service on each node.</strong></p><p><strong>4. Configure HAProxy as a load balancer for the cluster.</strong></p><p><strong>5. Destroy The Cluster</strong></p><p><strong>Advantages of this deployment method:</strong></p><ul><li><strong>High availability:</strong> The cluster can tolerate the failure of one or more nodes without affecting data availability.</li><li><strong>Scalability:</strong> The cluster can be easily scaled by adding more nodes.</li><li><strong>Performance:</strong> The use of multiple disks can improve the performance of the cluster.</li></ul><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/minio/VM">https://github.com/viethqb/data-platform-notes/tree/main/minio/VM</a></p><blockquote><strong>IMPORTANT: Convention for Bash Scripts</strong></blockquote><blockquote>Throughout this series, the following convention applies to Bash scripts:</blockquote><blockquote>Commands in the form “&gt; command” should be executed on the local laptop.</blockquote><blockquote>Commands in the form “root@kworker1 command” should be executed on the kworker1 VM/Container as the root user.</blockquote><h4>1. Provision virtual machines using Vagrant and VirtualBox</h4><p>Vagrantfile</p><pre># -*- mode: ruby -*-<br># vi: set ft=ruby :<br><br>ENV[&#39;VAGRANT_NO_PARALLEL&#39;] = &#39;yes&#39;<br><br>Vagrant.configure(2) do |config|<br><br>  config.vm.provision &quot;shell&quot;, path: &quot;bootstrap.sh&quot;<br><br>  # Load Balancer Node<br>  config.vm.define &quot;loadbalancer&quot; do |lb|<br>    lb.vm.box = &quot;generic/ubuntu2204&quot;<br>    lb.vm.hostname = &quot;loadbalancer&quot;<br>    lb.vm.network &quot;private_network&quot;, ip: &quot;172.16.16.100&quot;<br>    lb.vm.provider &quot;virtualbox&quot; do |v|<br>      v.name = &quot;loadbalancer&quot;<br>      v.memory = 2048<br>      v.cpus = 1<br>    end<br>  end<br>  <br>  # Number of Minio VMs<br>  MinioCount = 4<br><br>  # Configure Minio VMs<br>  (1..MinioCount).each do |i|<br>    config.vm.define &quot;minio#{i}&quot; do |minionode|<br>      minionode.vm.box = &quot;generic/ubuntu2204&quot;<br>      minionode.vm.hostname = &quot;minio#{i}&quot;<br>      minionode.vm.network &quot;private_network&quot;, ip: &quot;172.16.16.10#{i}&quot;<br><br>      minionode.vm.provider &quot;virtualbox&quot; do |v|<br>        v.name = &quot;minio#{i}&quot;<br>        v.memory = 2048<br>        v.cpus = 2<br><br>        # Mount four disks for each VM<br>        (1..4).each do |disk_number|<br>          # Create disks using dedicated methods for specific storage controllers<br>          disk = &quot;/data/virtualbox/vms/minio#{i}/disk#{disk_number}.vdi&quot;<br>          unless File.exist? (disk)      <br>                v.customize [&#39;createhd&#39;, &#39;--filename&#39;, disk, &#39;--size&#39;, 20 * 1024]<br>          end<br>          v.customize [&#39;storageattach&#39;, :id, &#39;--storagectl&#39;, &#39;SATA Controller&#39;, &#39;--port&#39;, disk_number, &#39;--device&#39;, 0, &#39;--type&#39;,  &#39;hdd&#39;, &#39;--medium&#39;, disk]<br><br>        end<br>      end<br>    end<br>  end<br>end</pre><p>Start virtual machines</p><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/minio/VM<br>&gt; vagrant up <br><br># vboxmanage list hdds<br># vboxmanage closemedium &lt;UUID&gt; --delete <br>&gt; ssh-copy-id root@172.16.16.100<br>&gt; ssh-copy-id root@172.16.16.101<br>&gt; ssh-copy-id root@172.16.16.102<br>&gt; ssh-copy-id root@172.16.16.103<br>&gt; ssh-copy-id root@172.16.16.104</pre><h4>2. Create mount points and mount the corresponding disks to the mount points</h4><p>Run on minio1</p><ul><li><strong><em>lsblk</em></strong> lists information about all available or the specified block devices.</li></ul><pre>root@minio1:~# lsblk</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*-r7ISAXVvDVjaHz3KmfTmg.png" /></figure><p>=&gt; sdb, sdc, sdd, sde are the storage disk for minio1.</p><p>=&gt; mount sdb, sdc, sdd, sde to /data/minio/data-1, /data/minio/data-2, /data/minio/data-3, /data/minio/data-4</p><pre># Create mount point<br>root@minio1:~# mkdir -p /data/minio/data-1<br>root@minio1:~# mkdir -p /data/minio/data-2<br>root@minio1:~# mkdir -p /data/minio/data-3<br>root@minio1:~# mkdir -p /data/minio/data-4<br>root@minio1:~# mkfs.xfs /dev/sdb<br>root@minio1:~# mkfs.xfs /dev/sdc<br>root@minio1:~# mkfs.xfs /dev/sdd<br>root@minio1:~# mkfs.xfs /dev/sde<br><br># mount disk to mountpoints<br>root@minio1:~# echo &quot;/dev/sdb /data/minio/data-1 xfs defaults,noatime,nofail 0 0&quot; &gt;&gt; /etc/fstab<br>root@minio1:~# echo &quot;/dev/sdc /data/minio/data-2 xfs defaults,noatime,nofail 0 0&quot; &gt;&gt; /etc/fstab<br>root@minio1:~# echo &quot;/dev/sdd /data/minio/data-3 xfs defaults,noatime,nofail 0 0&quot; &gt;&gt; /etc/fstab<br>root@minio1:~# echo &quot;/dev/sde /data/minio/data-4 xfs defaults,noatime,nofail 0 0&quot; &gt;&gt; /etc/fstab<br>root@minio1:~# mount -a<br>root@minio1:~# lsblk </pre><p>Repeat with minio 2, 3, 4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIukBaGBx3rCQ0E9xexXBQ.png" /></figure><h4>3. Start the minio service</h4><p>docker-compose.minio1.yaml</p><pre>services:<br>  minio1: <br>    hostname: minio1 <br>    container_name: minio1<br>    image: quay.io/minio/minio:RELEASE.2024-03-30T09-41-56Z<br>    command: server --console-address &quot;:9001&quot; http://minio{1...4}/data-{1...4}<br>    ports:<br>      - &quot;9000:9000&quot;<br>      - &quot;9001:9001&quot;<br>    extra_hosts:<br>      - &quot;minio1:172.16.16.101&quot;<br>      - &quot;minio2:172.16.16.102&quot;<br>      - &quot;minio3:172.16.16.103&quot;<br>      - &quot;minio4:172.16.16.104&quot;<br>    environment:<br>      MINIO_ROOT_USER: admin<br>      MINIO_ROOT_PASSWORD: password<br>    volumes:<br>      - /data/minio/data-1:/data-1<br>      - /data/minio/data-2:/data-2<br>      - /data/minio/data-3:/data-3<br>      - /data/minio/data-4:/data-4<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://localhost:9000/minio/health/live&quot;]<br>      interval: 30s<br>      timeout: 20s<br>      retries: 3</pre><p>docker-compose.minio2.yaml</p><pre>services:<br>  minio2:<br>    hostname: minio2 <br>    container_name: minio2<br>    image: quay.io/minio/minio:RELEASE.2024-03-30T09-41-56Z<br>    command: server --console-address &quot;:9001&quot; http://minio{1...4}/data-{1...4}<br>    ports:<br>      - &quot;9000:9000&quot;<br>      - &quot;9001:9001&quot;<br>    extra_hosts:<br>      - &quot;minio1:172.16.16.101&quot;<br>      - &quot;minio2:172.16.16.102&quot;<br>      - &quot;minio3:172.16.16.103&quot;<br>      - &quot;minio4:172.16.16.104&quot;<br>    environment:<br>      MINIO_ROOT_USER: admin<br>      MINIO_ROOT_PASSWORD: password<br>    volumes:<br>      - /data/minio/data-1:/data-1<br>      - /data/minio/data-2:/data-2<br>      - /data/minio/data-3:/data-3<br>      - /data/minio/data-4:/data-4<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://localhost:9000/minio/health/live&quot;]<br>      interval: 30s<br>      timeout: 20s<br>      retries: 3</pre><p>docker-compose.minio3.yaml</p><pre>services:<br>  minio3:<br>    hostname: minio3<br>    container_name: minio3<br>    image: quay.io/minio/minio:RELEASE.2024-03-30T09-41-56Z<br>    command: server --console-address &quot;:9001&quot; http://minio{1...4}/data-{1...4}<br>    ports:<br>      - &quot;9000:9000&quot;<br>      - &quot;9001:9001&quot;<br>    extra_hosts:<br>      - &quot;minio1:172.16.16.101&quot;<br>      - &quot;minio2:172.16.16.102&quot;<br>      - &quot;minio3:172.16.16.103&quot;<br>      - &quot;minio4:172.16.16.104&quot;<br>    environment:<br>      MINIO_ROOT_USER: admin<br>      MINIO_ROOT_PASSWORD: password<br>    volumes:<br>      - /data/minio/data-1:/data-1<br>      - /data/minio/data-2:/data-2<br>      - /data/minio/data-3:/data-3<br>      - /data/minio/data-4:/data-4<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://localhost:9000/minio/health/live&quot;]<br>      interval: 30s<br>      timeout: 20s<br>      retries: 3</pre><p>docker-compose.minio4.yaml</p><pre>services:<br>  minio4:<br>    hostname: minio4<br>    container_name: minio4<br>    image: quay.io/minio/minio:RELEASE.2024-03-30T09-41-56Z<br>    command: server --console-address &quot;:9001&quot; http://minio{1...4}/data-{1...4}<br>    ports:<br>      - &quot;9000:9000&quot;<br>      - &quot;9001:9001&quot;<br>    extra_hosts:<br>      - &quot;minio1:172.16.16.101&quot;<br>      - &quot;minio2:172.16.16.102&quot;<br>      - &quot;minio3:172.16.16.103&quot;<br>      - &quot;minio4:172.16.16.104&quot;<br>    environment:<br>      MINIO_ROOT_USER: admin<br>      MINIO_ROOT_PASSWORD: password<br>    volumes:<br>      - /data/minio/data-1:/data-1<br>      - /data/minio/data-2:/data-2<br>      - /data/minio/data-3:/data-3<br>      - /data/minio/data-4:/data-4<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://localhost:9000/minio/health/live&quot;]<br>      interval: 30s<br>      timeout: 20s<br>      retries: 3</pre><p>Copy the docker-compose file corresponding to each node</p><pre>&gt; scp docker-compose.minio1.yaml root@172.16.16.101:~<br>&gt; scp docker-compose.minio2.yaml root@172.16.16.102:~<br>&gt; scp docker-compose.minio3.yaml root@172.16.16.103:~<br>&gt; scp docker-compose.minio4.yaml root@172.16.16.104:~</pre><p>Install Docker in all minio node</p><pre>root@minio1:~# curl -fsSL https://get.docker.com -o get-docker.sh<br>root@minio1:~# sh get-docker.sh<br><br>root@minio2:~# curl -fsSL https://get.docker.com -o get-docker.sh<br>root@minio2:~# sh get-docker.sh<br><br>root@minio3:~# curl -fsSL https://get.docker.com -o get-docker.sh<br>root@minio3:~# sh get-docker.sh<br><br>root@minio4:~# curl -fsSL https://get.docker.com -o get-docker.sh<br>root@minio4:~# sh get-docker.sh</pre><p>Start the minio service</p><pre>root@minio1:~# docker compose -f docker-compose.minio1.yaml up -d<br>root@minio1:~# docker logs -f minio1<br><br>root@minio2:~# docker compose -f docker-compose.minio2.yaml up -d<br>root@minio2:~# docker logs -f minio2<br><br>root@minio3:~# docker compose -f docker-compose.minio3.yaml up -d<br>root@minio3:~# docker logs -f minio3<br><br>root@minio4:~# docker compose -f docker-compose.minio4.yaml up -d<br>root@minio4:~# docker logs -f minio4</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rzofn1WDfpG-jVNxCs3y-Q.png" /><figcaption>Start the minio service</figcaption></figure><h4>4. Configure HAProxy as a load balancer for the cluster</h4><pre>root@loadbalancer:~# apt-get update -qq &amp;&amp; apt-get install -y haproxy -qq<br>root@loadbalancer:~# cat &gt;&gt;/etc/haproxy/haproxy.cfg&lt;&lt;EOF<br><br>frontend minio-frontend<br>    bind *:9000<br>    mode tcp<br>    option tcplog<br>    default_backend minio-backend<br><br>backend minio-backend<br>    mode tcp<br>    option tcp-check<br>    balance roundrobin<br>    server minio-1 172.16.16.101:9000 check fall 3 rise 2<br>    server minio-2 172.16.16.102:9000 check fall 3 rise 2<br>    server minio-3 172.16.16.103:9000 check fall 3 rise 2<br>    server minio-4 172.16.16.104:9000 check fall 3 rise 2<br> <br>frontend minio-console-frontend<br>    bind *:9001<br>    mode tcp<br>    option tcplog<br>    default_backend minio-console-backend<br><br>backend minio-console-backend<br>    mode tcp<br>    option tcp-check<br>    balance roundrobin<br>    server minio-1 172.16.16.101:9001 check fall 3 rise 2<br>    server minio-2 172.16.16.102:9001 check fall 3 rise 2<br>    server minio-3 172.16.16.103:9001 check fall 3 rise 2<br>    server minio-4 172.16.16.104:9001 check fall 3 rise 2<br>EOF<br>root@loadbalancer:~# systemctl enable haproxy.service<br>root@loadbalancer:~# systemctl restart haproxy.service</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8G-mvzYT3myF8j2xk8ubZQ.png" /></figure><p>Access Minio at <a href="http://172.16.16.100:9001/">http://172.16.16.100:9001/</a> in your web browser with user: admin &amp; password: password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fiVcYkSowz5wuAxM8On_fw.png" /></figure><h4>5. Destroy The Cluster</h4><pre>&gt; vagrant destroy -f</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6eFUlX-gIzrq4DvO_pw9Ew.png" /></figure><h3>Conclusion</h3><p>In this article, I’ve outlined the deployment of a multi-node, multi-disk MinIO cluster. We’ve explored the benefits of this approach including high availability, scalability, and performance improvements.</p><p>To enhance your MinIO cluster even further, here are some additional configurations we’ll delve into in a future article:</p><ul><li><strong>HTTPS Configuration:</strong> Establishing secure communication between clients and the MinIO cluster using HTTPS is crucial. We’ll explore how to configure HTTPS for your MinIO deployment.</li><li><strong>Monitoring with Prometheus:</strong> Proactive monitoring is essential for maintaining a healthy MinIO cluster. We’ll discuss how to integrate Prometheus to monitor key metrics and ensure optimal cluster performance.</li></ul><p>By incorporating these configurations, you can strengthen the security and observability of your MinIO deployment.</p><p>In the next article, we will deploy Hive Metastore, Trino, and configure Trino to read and write Apache Iceberg table formats. This is a <strong>very important</strong> part of a data platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ceca1d9f81e0" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-3-main-components-install-distributed-minio-cluster-ceca1d9f81e0">[Kubernetes Data Platform][Part 3][Main Components]: Install Distributed MinIO Cluster</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 2.4]: Creating highly available Kubernetes cluster with k3s]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-2-4-creating-highly-available-kubernetes-cluster-with-k3s-0ed1f36e20e2?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ed1f36e20e2</guid>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-lakehouse]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Sat, 03 Aug 2024 00:15:19 GMT</pubDate>
            <atom:updated>2024-08-25T17:37:41.820Z</atom:updated>
            <content:encoded><![CDATA[<p>This guide outlines deploying a highly available (HA) Kubernetes cluster using k3s on virtual machine-like containers. To achieve high availability, we leverage a software component called kube-vip. Kube-vip acts as both the cluster’s virtual IP address and the load balancer. This eliminates the need for additional external hardware or software, streamlining deployment and management.</p><p>k3s is a lightweight, production-grade Kubernetes distribution designed for resource-constrained environments like remote locations, IoT appliances, or unattended deployments. Packaged as a single binary under 70MB, k3s simplifies installation, operation, and automatic updates for Kubernetes clusters. It supports both ARM64 and ARMv7 architectures.</p><p><em>The architecture is as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gg9cahm3kKWuwucj2zciWA.png" /><figcaption>K3s HA cluster</figcaption></figure><h3>INSTALLATION STEPS</h3><p><strong>1. Creating Virtual Machine-like Containers:</strong></p><ul><li>We’ll use docker-compose and sysbox to create seven VM-like containers: Master Nodes (IPs: 172.25.1.3, 172.25.1.4, 172.25.1.5), Worker Nodes (IPs: 172.25.1.6, 172.25.1.7, 172.25.1.8)</li><li>Detailed instructions are provided in the docker-compose.yaml file.</li></ul><p><strong>2. Preparing the First Master Node (Master-1):</strong></p><ul><li>This step involves installing the first k3s server on the Master-1 container.</li><li>Config kube-vip (IPs: 172.25.1.2)</li></ul><p><strong>3. Configuring Remaining Master Nodes (Master-2 &amp; Master-3):</strong></p><ul><li>Install the k3s server on both Master-2 and Master-3 containers.</li></ul><p><strong>4. Preparing Worker Nodes (Worker-1, Worker-2, Worker-3):</strong></p><ul><li>Install the k3s agent on each Worker container.</li></ul><p><strong>5. Installing Basic Kubernetes Components:</strong></p><ul><li>Nginx Ingress Controller</li><li>Storage Provisioner</li><li>Metrics Server</li></ul><p><strong>6. Installing Testing Tools:</strong></p><ul><li>Tools to verify cluster functionality will be installed.</li></ul><p><strong>7. Destroying the Cluster</strong></p><ul><li>Instructions on how to destroy the deployed cluster will be provided.</li></ul><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/kubernetes/k3s">https://github.com/viethqb/data-platform-notes/tree/main/kubernetes/k3s</a></p><blockquote><strong>IMPORTANT: Convention for Bash Scripts</strong></blockquote><blockquote>Throughout this series, the following convention applies to Bash scripts:</blockquote><blockquote>Commands in the form “&gt; command” should be executed on the local laptop.</blockquote><blockquote>Commands in the form “root@kworker1 command” should be executed on the kworker1 VM/Container as the root user.</blockquote><h4>1. Creating Virtual Machine-like Containers</h4><p>docker-compose.yaml</p><pre>services:<br>  loadbalancer:<br>    hostname: loadbalancer<br>    container_name: loadbalancer<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      k3s_network:<br>        ipv4_address: 172.25.1.2<br>  master-1:<br>    hostname: master-1<br>    container_name: master-1<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      k3s_network:<br>        ipv4_address: 172.25.1.3<br>  master-2:<br>    hostname: master-2<br>    container_name: master-2<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      k3s_network:<br>        ipv4_address: 172.25.1.4<br>  master-3:<br>    hostname: master-3<br>    container_name: master-3<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      k3s_network:<br>        ipv4_address: 172.25.1.5<br>  worker-1:<br>    hostname: worker-1<br>    container_name: worker-1<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      k3s_network:<br>        ipv4_address: 172.25.1.6<br>  worker-2:<br>    hostname: worker-2<br>    container_name: worker-2<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      k3s_network:<br>        ipv4_address: 172.25.1.7<br>  worker-3:<br>    hostname: worker-3<br>    container_name: worker-3<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      k3s_network:<br>        ipv4_address: 172.25.1.8<br>networks:<br>  k3s_network:<br>    driver: bridge<br>    ipam:<br>     config:<br>       - subnet: 172.25.1.0/24<br>         gateway: 172.25.1.1</pre><p>Dockerfile</p><pre>FROM ghcr.io/nestybox/ubuntu-jammy-systemd:latest<br><br># Install Sshd<br>RUN apt-get update \<br>    &amp;&amp; apt-get install --no-install-recommends -y openssh-server uuid-runtime\<br>    apt-transport-https \<br>    bash-completion vim less man jq bc \<br>    lsof tree psmisc htop lshw sysstat dstat \<br>    iproute2 iputils-ping iptables dnsutils traceroute \<br>    netcat curl wget nmap socat netcat-openbsd rsync \<br>    p7zip-full \<br>    git tig \<br>    binutils acl pv \<br>    strace tcpdump \<br>    open-iscsi nfs-common \<br>    &amp;&amp; rm -rf /var/lib/apt/lists/* \<br>    &amp;&amp; mkdir /home/admin/.ssh \<br>    &amp;&amp; chown admin:admin /home/admin/.ssh<br><br># Enable sudo without password<br>RUN echo &#39;%sudo ALL=(ALL) NOPASSWD:ALL&#39; &gt;&gt; /etc/sudoers<br><br># Enable ssh password authentication<br>RUN sed -i &#39;s/^PasswordAuthentication .*/PasswordAuthentication yes/&#39; /etc/ssh/sshd_config<br>RUN echo &#39;PermitRootLogin yes&#39; &gt;&gt; /etc/ssh/sshd_config<br><br># Set Root password<br>RUN echo &quot;admin\nadmin&quot; | passwd root<br><br>EXPOSE 22<br><br># Set systemd as entrypoint.<br>ENTRYPOINT [&quot;/sbin/init&quot;, &quot;--log-level=err&quot;]</pre><p>Creating Virtual Machine-like Containers</p><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/kubernetes/k3s<br><br>&gt; docker-compose up -d<br>&gt; docker ps -q | xargs -n 1 docker inspect --format &#39;{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}&#39; | sed &#39;s/ \// /&#39;<br>#ssh user: admin(root)/admin<br><br>&gt; ssh-copy-id root@172.25.1.3<br>&gt; ssh-copy-id root@172.25.1.4<br>&gt; ssh-copy-id root@172.25.1.5<br>&gt; ssh-copy-id root@172.25.1.6<br>&gt; ssh-copy-id root@172.25.1.7<br>&gt; ssh-copy-id root@172.25.1.8 <br><br>&gt; ssh root@172.25.1.3 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.1.4 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.1.5 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.1.6 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.1.7 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.1.8 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YznF6Yoq46PBjPnV98h5Eg.png" /></figure><h4>2. Preparing the First Master Node (Master-1)</h4><pre>root@master-1:~# curl -sfL https://get.k3s.io | K3S_TOKEN=DC87A250BCBA499994CF808CEADD1BCC sh -s - server \<br>    --cluster-init \<br>    --disable traefik --disable servicelb \<br>    --tls-san=172.25.1.2<br><br># Install kube-vip<br>root@master-1:~# kubectl apply -f https://kube-vip.io/manifests/rbac.yaml<br>root@master-1:~# export VIP=172.25.1.2<br>root@master-1:~# ip a<br># Find the network interface corresponding to IP 172.25.1.3<br>root@master-1:~# export INTERFACE=eth0<br>root@master-1:~# crictl -r &quot;unix:///run/k3s/containerd/containerd.sock&quot;  pull ghcr.io/kube-vip/kube-vip:latest<br>root@master-1:~# CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock  ctr -n k8s.io run \<br>--rm \<br>--net-host \<br>ghcr.io/kube-vip/kube-vip:latest vip /kube-vip manifest daemonset --arp --interface $INTERFACE --address $VIP --controlplane  --leaderElection --taint --services --inCluster | tee /var/lib/rancher/k3s/server/manifests/kube-vip.yaml<br><br>root@master-1:~# kubectl get ds -n kube-system kube-vip-ds</pre><h4>3. Configuring Remaining Master Nodes (Master-2 &amp; Master-3)</h4><pre>root@master-2:~# curl -sfL https://get.k3s.io | K3S_TOKEN=DC87A250BCBA499994CF808CEADD1BCC sh -s - server \<br>    --server https://172.25.1.3:6443 \<br>    --disable traefik --disable servicelb \<br>    --tls-san=172.25.1.2<br>    <br>root@master-3:~# curl -sfL https://get.k3s.io | K3S_TOKEN=DC87A250BCBA499994CF808CEADD1BCC sh -s - server \<br>    --server https://172.25.1.3:6443 \<br>    --disable traefik --disable servicelb \<br>    --tls-san=172.25.1.2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rnqe0DLOpu0XKPlE4u9DdQ.png" /></figure><h4>4. Adding Worker Nodes (Worker-1, Worker-2, Worker-3)</h4><pre>root@worker-1:~# curl -sfL https://get.k3s.io | K3S_TOKEN=DC87A250BCBA499994CF808CEADD1BCC sh -s - agent --server https://172.25.1.2:6443<br>root@worker-2:~# curl -sfL https://get.k3s.io | K3S_TOKEN=DC87A250BCBA499994CF808CEADD1BCC sh -s - agent --server https://172.25.1.2:6443<br>root@worker-3:~# curl -sfL https://get.k3s.io | K3S_TOKEN=DC87A250BCBA499994CF808CEADD1BCC sh -s - agent --server https://172.25.1.2:6443</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-YQWktwhSOz4h_7V1RVkA.png" /></figure><h4>5. Installing Basic Kubernetes Components</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_VW9ljcb1vVMUYgM_7-6Nw.png" /></figure><p>Since k3s comes pre-installed with storage class and metric servers, we only need to install the Nginx Ingress Controller.</p><p>Install the Nginx Ingress Controller</p><pre>#Install Helm cli<br>root@master-1:~# curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3<br>root@master-1:~# bash ./get_helm.sh <br><br># Install ingress nginx<br>root@master-1:~# helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx<br>root@master-1:~# helm repo update<br>root@master-1:~# export KUBECONFIG=/var/lib/rancher/k3s/server/cred/admin.kubeconfig<br>root@master-1:~# helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=true,controller.service.type=&quot;&quot;,controller.kind=DaemonSet --namespace ingress-nginx --version 4.10.1 --create-namespace --debug<br>root@master-1:~# kubectl -n ingress-nginx get all<br>root@master-1:~# kubectl get IngressClass</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ys7nC_Kh26vc-C_6ebOmAQ.png" /></figure><h4>6. Install testing tools</h4><p>minio-values.yaml</p><pre><br>auth:<br>  rootUser: &quot;admin&quot;<br>  rootPassword: &quot;password&quot;<br>ingress:<br>  enabled: true<br>  ingressClassName: &quot;nginx&quot;<br>  hostname: minio.lakehouse.local<br>  annotations:<br>    nginx.ingress.kubernetes.io/proxy-body-size: 1024m<br>defaultBuckets: &quot;lakehouse, airflow, risingwave, kafka&quot;<br>persistence:<br>  size: 50Gi</pre><p>Install Minio on Kubernetes</p><pre><br># Install Minio<br>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f minio-values.yaml bitnami/minio --create-namespace --debug<br><br>&gt; kubectl -n minio get all -owide<br>&gt; kubectl -n minio get pvc<br>&gt; kubectl -n minio get ing<br><br># Update local hosts file <br>&gt; sudo vim /etc/hosts<br># 172.25.1.6   minio.lakehouse.local<br><br><br># Access Minio at http://minio.lakehouse.local in your web browser.<br># user/pass: admin/password</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MM0ETk9WxvRO-wX3Jrki4A.png" /></figure><h3>Conclusion</h3><p>We’ve concluded our exploration of deploying Kubernetes in production environments. Throughout this series, we’ve delved into various aspects including:</p><ul><li><strong>Deployment methods:</strong> kubeadm, k3s, k0s, and rke2.</li><li><strong>Load balancing:</strong> HAProxy and kube-vip.</li><li><strong>Virtualization:</strong> Vagrant + VirtualBox, Multipass, and Docker + sysbox runtime.</li></ul><p>It’s worth noting that in real-world settings, you’ll often receive pre-configured virtual machines from system administrators or DevOps teams.</p><p>We’ve also covered essential Kubernetes components such as:</p><ul><li><strong>Nginx Ingress Controller:</strong> For exposing HTTP services.</li><li><strong>Storage classes:</strong> Longhorn and local-path-provisioner.</li><li><strong>Metric Server:</strong> For monitoring cluster metrics.</li><li><strong>Minio:</strong> As a practical demonstration of Kubernetes functionality.</li></ul><p>As we’ve established, our primary goal in this series is to establish a robust Data Platform. Therefore, to align with this objective, we’ll shift our focus in the next installment to deploying data services. Stay tuned for the upcoming chapter!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ed1f36e20e2" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-2-4-creating-highly-available-kubernetes-cluster-with-k3s-0ed1f36e20e2">[Kubernetes Data Platform][Part 2.4]: Creating highly available Kubernetes cluster with k3s</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Kubernetes Data Platform][Part 2.3]: Creating highly available Kubernetes cluster with rke2]]></title>
            <link>https://towardsdev.com/kubernetes-data-platform-part-2-3-creating-highly-available-kubernetes-cluster-with-rke2-4a0c4490a90f?source=rss-dfeb01b4d84c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a0c4490a90f</guid>
            <category><![CDATA[rancher]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[rke2]]></category>
            <dc:creator><![CDATA[Viet_1846]]></dc:creator>
            <pubDate>Fri, 02 Aug 2024 00:50:15 GMT</pubDate>
            <atom:updated>2024-08-21T15:37:36.195Z</atom:updated>
            <content:encoded><![CDATA[<p>This guide provides a step-by-step approach to deploying a highly available (HA) Kubernetes cluster using rke2. The cluster will utilize “VM-like” containers using docker-compose and sysbox.</p><p>For high availability, kube-vip will act as the cluster’s virtual IP and load balancer. This eliminates the need for external hardware or software, simplifying deployment and management.</p><h3>Deeper Dive into Technologies Used:</h3><p><a href="https://github.com/rancher/rke2"><strong>Rke2 (Rancher Kubernetes Engine, 2nd Generation):</strong></a></p><p>Rancher’s next-generation Kubernetes distribution built for security and compliance. Designed specifically for the U.S. Federal Government sector, rke2 is a fully conformant Kubernetes distribution.</p><p><a href="https://github.com/nestybox/sysbox"><strong>Sysbox:</strong></a></p><p>Sysbox is an open-source, free container runtime that enhances container security and functionality. Originally developed by Nestybox, Sysbox offers two key advantages:</p><ul><li><strong>Improved Container Isolation:</strong> Sysbox utilizes Linux user namespaces for all containers. This ensures the container’s “root user” has no privileges on the host system, significantly improving isolation.</li><li><strong>Enhanced Workload Capabilities:</strong> Unlike traditional containers, Sysbox allows you to run system-level software directly within the container. This includes programs like systemd, Docker, Kubernetes, K3s, buildx, legacy applications, and more. This functionality eliminates the need for modifications or special versions of the software, simplifying deployment. Additionally, Sysbox virtualizes portions of the container’s file systems (procfs &amp; sysfs) and hides host information, further enhancing security. The runtime also locks initial mounts within the container, providing an additional layer of protection.</li></ul><p><strong>Benefits of Sysbox:</strong></p><ul><li>Enables containers to run workloads traditionally reserved for virtual machines.</li><li>Simplifies deployment by allowing unmodified, standard software versions within containers.</li><li>Eliminates the need for privileged containers, complex images, tricky entrypoints, and special volume mounts.</li></ul><p><a href="https://kube-vip.io/"><strong>Kube-vip</strong></a><strong>:</strong> A Kubernetes add-on that provides a virtual IP and load balancing functionality for both the control plane (enabling HA) and LoadBalancer type Kubernetes services, simplifying deployment and reducing external dependencies.</p><p><em>RKE2 HA With VIP Load Balance Architecture:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3wOENgZ-uv1XH-JYmaz8Q.png" /></figure><h3>INSTALLATION STEPS</h3><ol><li><strong>Create “VM-like” containers using docker-compose and sysbox. (Details in </strong><strong>docker-compose.yaml)</strong></li><li>This will create 6 “VM-like” containers: master-1(172.25.2.3), master-2(172.25.2.4), master-3(172.25.2.5), worker-1(172.25.2.6), worker-2(172.25.2.7), worker-3(172.25.2.8).</li><li><strong>Prepare First Control Plane Node (Master 1)</strong></li><li><strong>Deploy kube-vip</strong> VIP(172.25.2.2)</li><li><strong>Configure Remaining Control-Plane Nodes (Master 2, 3)</strong></li><li><strong>Deploy Worker Nodes (Worker 1, 2, 3)</strong></li><li><strong>Install basic Kubernetes components</strong></li><li><strong>Install testing tools</strong></li><li><strong>Destroy the cluster</strong></li></ol><h3>HANDS-ON STEP</h3><p><strong>Reference Repository:</strong> <a href="https://github.com/viethqb/data-platform-notes/tree/main/kubernetes/rke2">https://github.com/viethqb/data-platform-notes/tree/main/kubernetes/rke2</a></p><blockquote><strong>IMPORTANT: Convention for Bash Scripts</strong></blockquote><blockquote>Throughout this series, the following convention applies to Bash scripts:</blockquote><blockquote>Commands in the form “&gt; command” should be executed on the local laptop.</blockquote><blockquote>Commands in the form “root@kworker1 command” should be executed on the kworker1 VM as the root user.</blockquote><h4>1. Create “VM-like” containers using docker-compose and sysbox</h4><p>docker-compose.yaml</p><pre>services:<br>  master-1:<br>    hostname: master-1<br>    container_name: master-1<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      kubernetes_network:<br>        ipv4_address: 172.25.2.3<br>  master-2:<br>    hostname: master-2<br>    container_name: master-2<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      kubernetes_network:<br>        ipv4_address: 172.25.2.4<br>  master-3:<br>    hostname: master-3<br>    container_name: master-3<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      kubernetes_network:<br>        ipv4_address: 172.25.2.5<br>  worker-1:<br>    hostname: worker-1<br>    container_name: worker-1<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      kubernetes_network:<br>        ipv4_address: 172.25.2.6<br>  worker-2:<br>    hostname: worker-2<br>    container_name: worker-2<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      kubernetes_network:<br>        ipv4_address: 172.25.2.7<br>  worker-3:<br>    hostname: worker-3<br>    container_name: worker-3<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    runtime: sysbox-runc<br>    networks:<br>      kubernetes_network:<br>        ipv4_address: 172.25.2.8<br>networks:<br>  kubernetes_network:<br>    driver: bridge<br>    ipam:<br>     config:<br>       - subnet: 172.25.2.0/24<br>         gateway: 172.25.2.1</pre><p>Dockerfile</p><pre>FROM ghcr.io/nestybox/ubuntu-jammy-systemd:latest<br><br># Install Sshd<br>RUN apt-get update \<br>    &amp;&amp; apt-get install --no-install-recommends -y openssh-server uuid-runtime\<br>    apt-transport-https \<br>    bash-completion vim less man jq bc \<br>    lsof tree psmisc htop lshw sysstat dstat \<br>    iproute2 iputils-ping iptables dnsutils traceroute \<br>    netcat curl wget nmap socat netcat-openbsd rsync net-tools telnet\<br>    p7zip-full \<br>    git tig \<br>    binutils acl pv \<br>    strace tcpdump \<br>    open-iscsi nfs-common \<br>    &amp;&amp; rm -rf /var/lib/apt/lists/* \<br>    &amp;&amp; mkdir /home/admin/.ssh \<br>    &amp;&amp; chown admin:admin /home/admin/.ssh<br><br># Enable sudo without password<br>RUN echo &#39;%sudo ALL=(ALL) NOPASSWD:ALL&#39; &gt;&gt; /etc/sudoers<br><br># Enable ssh password authentication<br>RUN sed -i &#39;s/^PasswordAuthentication .*/PasswordAuthentication yes/&#39; /etc/ssh/sshd_config<br>RUN echo &#39;PermitRootLogin yes&#39; &gt;&gt; /etc/ssh/sshd_config<br><br># Set Root password<br>RUN echo &quot;admin\nadmin&quot; | passwd root<br><br>EXPOSE 22<br><br># Set systemd as entrypoint.<br>ENTRYPOINT [&quot;/sbin/init&quot;, &quot;--log-level=err&quot;]</pre><p>Start “VM-like” containers</p><pre>&gt; cd  ~/Documents <br>&gt; git clone https://github.com/viethqb/data-platform-notes.git<br>&gt; cd data-platform-notes/kubernetes/rke2<br>&gt; docker-compose up -d<br>&gt; docker ps -q | xargs -n 1 docker inspect --format &#39;{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}&#39; | sed &#39;s/ \// /&#39;<br>#ssh user: admin(root)/admin<br><br>&gt; ssh-copy-id root@172.25.2.3<br>&gt; ssh-copy-id root@172.25.2.4<br>&gt; ssh-copy-id root@172.25.2.5<br>&gt; ssh-copy-id root@172.25.2.6<br>&gt; ssh-copy-id root@172.25.2.7<br>&gt; ssh-copy-id root@172.25.2.8 <br><br>&gt; ssh root@172.25.2.3 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.2.4 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.2.5 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.2.6 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.2.7 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;<br>&gt; ssh root@172.25.2.8 &#39;echo $(uuidgen) &gt; /etc/machine-id&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sojYMxVQZ3hBJimxNxPDHw.png" /></figure><h4>2. Prepare First Control Plane Node (Master 1)</h4><p>Run on master-1</p><pre>&gt; ssh root@172.25.2.3<br>root@master-1:~# mkdir -p /etc/rancher/rke2/<br>root@master-1:~# mkdir -p  /var/lib/rancher/rke2/server/manifests/<br><br>root@master-1:~# cat&lt;&lt;EOF|tee /etc/rancher/rke2/config.yaml<br>tls-san:<br>  - 172.25.2.2<br>  - 172.25.2.3<br>  - 172.25.2.4<br>  - 172.25.2.5<br>write-kubeconfig-mode: &quot;0600&quot;<br>etcd-expose-metrics: true<br>cni:<br>  - canal<br>EOF<br><br>root@master-1:~# cat&lt;&lt;EOF| tee /var/lib/rancher/rke2/server/manifests/rke2-ingress-nginx-config.yaml<br>---<br>apiVersion: helm.cattle.io/v1<br>kind: HelmChartConfig<br>metadata:<br>  name: rke2-ingress-nginx<br>  namespace: kube-system<br>spec:<br>  valuesContent: |-<br>    controller:<br>      metrics:<br>        service:<br>          annotations:<br>            prometheus.io/scrape: &quot;true&quot;<br>            prometheus.io/port: &quot;10254&quot;<br>      config:<br>        use-forwarded-headers: &quot;true&quot;<br>      allowSnippetAnnotations: &quot;true&quot;<br>EOF<br><br>root@master-1:~# curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=server sh -<br>root@master-1:~# systemctl start rke2-server<br>root@master-1:~# systemctl enable rke2-server<br>root@master-1:~# echo &quot;export PATH=$PATH:/var/lib/rancher/rke2/bin&quot; &gt;&gt; $HOME/.bashrc<br>root@master-1:~# echo &quot;export KUBECONFIG=/etc/rancher/rke2/rke2.yaml&quot;  &gt;&gt; $HOME/.bashrc<br>root@master-1:~# cat /var/lib/rancher/rke2/server/node-token<br># K10320034a05e280ef37f0753cf1263586ae04d471a8b10a8d87f330150e0325475::server:c32246c40f9eb288ec6992065c971669</pre><p>Save this token for installation on other nodes:</p><pre>K10320034a05e280ef37f0753cf1263586ae04d471a8b10a8d87f330150e0325475::server:c32246c40f9eb288ec6992065c971669</pre><h4>3. Deploy kube-vip</h4><p>Run on master-1</p><pre>root@master-1:~# export VIP=172.25.2.2<br>root@master-1:~# ip a<br># Find the network interface corresponding to IP 172.25.2.3<br>root@master-1:~# export INTERFACE=eth0<br>root@master-1:~# curl https://kube-vip.io/manifests/rbac.yaml &gt; /var/lib/rancher/rke2/server/manifests/kube-vip-rbac.yaml<br>root@master-1:~# /var/lib/rancher/rke2/bin/crictl -r &quot;unix:///run/k3s/containerd/containerd.sock&quot;  pull ghcr.io/kube-vip/kube-vip:latest<br><br>root@master-1:~# CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock  ctr -n k8s.io run \<br>--rm \<br>--net-host \<br>ghcr.io/kube-vip/kube-vip:latest vip /kube-vip manifest daemonset --arp --interface $INTERFACE --address $VIP --controlplane  --leaderElection --taint --services --inCluster | tee /var/lib/rancher/rke2/server/manifests/kube-vip.yaml<br><br>root@master-1:~# source ~/.bashrc <br>root@master-1:~# kubectl rollout status daemonset kube-vip-ds -n kube-system --timeout=650s<br>root@master-1:~# kubectl get ds -n kube-system kube-vip-ds</pre><h4>4. Configure Remaining Control-Plane Nodes (Master 2, 3)</h4><p>Run on master-2</p><pre>root@master-2:~# mkdir -p /etc/rancher/rke2/<br>root@master-2:~# mkdir -p  /var/lib/rancher/rke2/server/manifests/<br><br>root@master-2:~# cat&lt;&lt;EOF|tee /etc/rancher/rke2/config.yaml<br>server: https://172.25.2.2:9345<br>token: &lt;token obtained in step 2 &gt;<br>write-kubeconfig-mode: &quot;0644&quot; <br>tls-san:<br>  - 172.25.2.2<br>  - 172.25.2.3<br>  - 172.25.2.4<br>  - 172.25.2.5<br>write-kubeconfig-mode: &quot;0644&quot;<br>etcd-expose-metrics: true<br>cni:<br>  - canal<br><br>EOF<br><br>root@master-2:~# cat&lt;&lt;EOF| tee /var/lib/rancher/rke2/server/manifests/rke2-ingress-nginx-config.yaml<br>---<br>apiVersion: helm.cattle.io/v1<br>kind: HelmChartConfig<br>metadata:<br>  name: rke2-ingress-nginx<br>  namespace: kube-system<br>spec:<br>  valuesContent: |-<br>    controller:<br>      metrics:<br>        service:<br>          annotations:<br>            prometheus.io/scrape: &quot;true&quot;<br>            prometheus.io/port: &quot;10254&quot;<br>      config:<br>        use-forwarded-headers: &quot;true&quot;<br>      allowSnippetAnnotations: &quot;true&quot;<br>EOF<br><br>root@master-2:~# curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=server sh -<br>root@master-2:~# systemctl start rke2-server<br>root@master-2:~# systemctl enable rke2-server<br><br>root@master-2:~# echo &quot;export PATH=$PATH:/var/lib/rancher/rke2/bin&quot; &gt;&gt; $HOME/.bashrc<br>root@master-2:~# echo &quot;export KUBECONFIG=/etc/rancher/rke2/rke2.yaml&quot;  &gt;&gt; $HOME/.bashrc <br>root@master-2:~# source ~/.bashrc</pre><p>Run on master-3</p><pre>root@master-3:~# mkdir -p /etc/rancher/rke2/<br>root@master-3:~# mkdir -p  /var/lib/rancher/rke2/server/manifests/<br><br>root@master-3:~# cat&lt;&lt;EOF|tee /etc/rancher/rke2/config.yaml<br>server: https://172.25.2.2:9345<br>token: &lt;token obtained in step 2&gt;<br>write-kubeconfig-mode: &quot;0644&quot; <br>tls-san:<br>  - 172.25.2.2<br>  - 172.25.2.3<br>  - 172.25.2.4<br>  - 172.25.2.5<br>write-kubeconfig-mode: &quot;0644&quot;<br>etcd-expose-metrics: true<br>cni:<br>  - canal<br><br>EOF<br><br>root@master-3:~# cat&lt;&lt;EOF| tee /var/lib/rancher/rke2/server/manifests/rke2-ingress-nginx-config.yaml<br>---<br>apiVersion: helm.cattle.io/v1<br>kind: HelmChartConfig<br>metadata:<br>  name: rke2-ingress-nginx<br>  namespace: kube-system<br>spec:<br>  valuesContent: |-<br>    controller:<br>      metrics:<br>        service:<br>          annotations:<br>            prometheus.io/scrape: &quot;true&quot;<br>            prometheus.io/port: &quot;10254&quot;<br>      config:<br>        use-forwarded-headers: &quot;true&quot;<br>      allowSnippetAnnotations: &quot;true&quot;<br>EOF<br><br>root@master-3:~# curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=server sh -<br>root@master-3:~# systemctl start rke2-server<br>root@master-3:~# systemctl enable rke2-server<br><br>root@master-3:~# echo &quot;export PATH=$PATH:/var/lib/rancher/rke2/bin&quot; &gt;&gt; $HOME/.bashrc<br>root@master-3:~# echo &quot;export KUBECONFIG=/etc/rancher/rke2/rke2.yaml&quot;  &gt;&gt; $HOME/.bashrc <br>root@master-3:~# source ~/.bashrc</pre><h4>5. Deploy Worker Nodes (Worker 1, 2, 3)</h4><p>Run on worker-1</p><pre>root@worker-1:~# mkdir -p /etc/rancher/rke2/<br><br>root@worker-1:~# cat&lt;&lt;EOF|tee /etc/rancher/rke2/config.yaml<br>server: https://172.25.2.2:9345<br>token: K10320034a05e280ef37f0753cf1263586ae04d471a8b10a8d87f330150e0325475::server:c32246c40f9eb288ec6992065c971669<br>write-kubeconfig-mode: \&quot;0644\&quot;<br>EOF<br><br>root@worker-1:~# curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=agent sh -<br>root@worker-1:~# systemctl start rke2-agent.service<br>root@worker-1:~# systemctl enable rke2-agent.service</pre><p>Run on worker-2</p><pre>root@worker-2:~# mkdir -p /etc/rancher/rke2/<br><br>root@worker-2:~# cat&lt;&lt;EOF|tee /etc/rancher/rke2/config.yaml<br>server: https://172.25.2.2:9345<br>token: &lt;token obtained in step 2&gt;<br>write-kubeconfig-mode: \&quot;0644\&quot;<br>EOF<br><br>root@worker-2:~# curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=agent sh -<br>root@worker-2:~# systemctl start rke2-agent.service<br>root@worker-2:~# systemctl enable  rke2-agent.service</pre><p>Run on worker-3</p><pre>root@worker-3:~# mkdir -p /etc/rancher/rke2/<br><br>root@worker-3:~# cat&lt;&lt;EOF|tee /etc/rancher/rke2/config.yaml<br>server: https://172.25.2.2:9345<br>token: &lt;token obtained in step 2&gt;<br>write-kubeconfig-mode: \&quot;0644\&quot;<br>EOF<br><br>root@worker-3:~# curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=agent sh -<br>root@worker-3:~# systemctl start rke2-agent.service<br>root@worker-3:~# systemctl enable  rke2-agent.service</pre><h4>6. Install basic Kubernetes components</h4><pre>&gt; scp root@172.25.2.3:/etc/rancher/rke2/rke2.yaml .<br>&gt; sed -i -e &#39;s/127.0.0.1/172.25.2.2/g&#39; ./rke2.yaml<br>&gt; k get no --kubeconfig ./rke2.yaml<br><br># Install local-path-storage<br>&gt; export KUBECONFIG=./rke2.yaml<br>&gt; kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.26/deploy/local-path-storage.yaml<br>&gt; kubectl patch storageclass local-path -p &#39;{&quot;metadata&quot;: {&quot;annotations&quot;:{&quot;storageclass.kubernetes.io/is-default-class&quot;:&quot;true&quot;}}}&#39;<br>&gt; kubectl get sc<br>&gt; kubectl get ingressclass<br>&gt; kubectl top no</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cAud_ThAIMN_2qnaqQJxlQ.png" /></figure><h4>7. Install testing tools</h4><p>minio-values.yaml</p><pre>auth:<br>  rootUser: &quot;admin&quot;<br>  rootPassword: &quot;password&quot;<br>ingress:<br>  enabled: true<br>  ingressClassName: &quot;nginx&quot;<br>  hostname: minio.lakehouse.local<br>  annotations:<br>    nginx.ingress.kubernetes.io/proxy-body-size: 1024m<br>defaultBuckets: &quot;lakehouse, airflow, risingwave, kafka&quot;<br>persistence:<br>  size: 50Gi</pre><p>Install Minio on Kubernetes</p><pre><br># Install Minio<br>&gt; helm repo add bitnami https://charts.bitnami.com/bitnami<br>&gt; helm repo update<br>&gt; helm upgrade --install minio -n minio -f minio-values.yaml bitnami/minio --create-namespace --debug<br><br>&gt; kubectl -n minio get all -owide<br>&gt; kubectl -n minio get pvc<br>&gt; kubectl -n minio get ing</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rq02PJd8IQ8MillS3zNwow.png" /></figure><p>Update local hosts file</p><pre>&gt; sudo vim /etc/hosts<br># Add the following lines to the end of the /etc/hosts<br># 172.25.2.6   minio.lakehouse.local</pre><p>Access Minio at <a href="http://minio.lakehouse.local/">http://minio.lakehouse.local</a> in your web browser with user: admin &amp; pass: password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MM0ETk9WxvRO-wX3Jrki4A.png" /></figure><h4>8. Destroy the cluster</h4><pre>&gt; docker-compose down</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3esY6NtSlSaf7BIH9_OoQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a0c4490a90f" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kubernetes-data-platform-part-2-3-creating-highly-available-kubernetes-cluster-with-rke2-4a0c4490a90f">[Kubernetes Data Platform][Part 2.3]: Creating highly available Kubernetes cluster with rke2</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>