2 minutes
Digitalocean Kubernetes Challenge 2021 - Harbor
Introduction
In this is guide i will explain how to create a Kubernetes Cluster on Digitalocean using Terraform, then i will deploy the Harbor on Cluster as a internal container registry
Terraform Files
the terraform code used to create the cluster
resource "digitalocean_kubernetes_cluster" "tayeh-cluster" {
name = "tayeh-cluster"
region = "fra1"
version = "1.21.5-do.0"
node_pool {
name = "worker-pool"
size = "s-1vcpu-2gb"
node_count = 3
auto_scale = true
min_nodes = 3
max_nodes = 4
}
}
after prepare the Terraform code execute this command to apply it
terraform init
export TF_VAR_do_token=<do_token>
terraform apply
now you can download the config on Digitalocean Kubernetes Cluster page, and try to connect to your cluster
[tayeh@fedora ~]$ kubectl --kubeconfig="tayeh-cluster-kubeconfig.yaml" get nodes
NAME STATUS ROLES AGE VERSION
worker-pool-uwtu0 Ready <none> 25m v1.21.5
worker-pool-uwtu1 Ready <none> 25m v1.21.5
worker-pool-uwtuz Ready <none> 25m v1.21.5
deploy Harbor to Cluster
first we need to install Helm using this command
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
Install ingress-nginx
controller
helm upgrade --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace ingress-nginx --create-namespace \
--kubeconfig=tayeh-cluster-kubeconfig.yaml
Get Nginx IP
kubectl get svc -n ingress-nginx --kubeconfig=tayeh-cluster-kubeconfig.yaml
point your DNS to the EXTERNAL-IP
harbor create value file
expose:
type: ingress
tls:
enabled: false
ingress:
hosts:
core: harbor.tayeh.me
notary: notary.tayeh.me
externalURL: http://harbor.tayeh.me
harborAdminPassword: "P@ssw0rd"
then Download Chart
helm repo add harbor https://helm.goharbor.io
helm install harbor harbor/harbor --values harbor.yml -n harbor --create-namespace --kubeconfig=tayeh-cluster-kubeconfig.yaml
kubectl patch ingress/harbor-ingress -p '{"spec": {"ingressClassName": "nginx"}}' -n harbor --kubeconfig=tayeh-cluster-kubeconfig.yaml
check containers using
[tayeh@fedora ~]$ kubectl --kubeconfig=tayeh-cluster-kubeconfig.yaml get pods -n harbor
NAME READY STATUS RESTARTS AGE
harbor-chartmuseum-7ddd5db67-2c7tf 1/1 Running 0 4m22s
harbor-core-6487f6cb4d-6qzz9 1/1 Running 0 4m22s
harbor-database-0 1/1 Running 0 4m22s
harbor-jobservice-5f7c6784f4-plrz6 1/1 Running 0 4m22s
harbor-notary-server-5466b7fc4-w5s8h 1/1 Running 2 4m22s
harbor-notary-signer-77797d55f6-kx6wh 1/1 Running 2 4m22s
harbor-portal-7dcf769575-6mjkd 1/1 Running 0 4m22s
harbor-redis-0 1/1 Running 0 4m22s
harbor-registry-7b7f7f547f-xvvmg 2/2 Running 0 4m22s
harbor-trivy-0 1/1 Running 0 4m22s
and now you can access harbor via hostname http://harbor.tayeh.me
teraaform and value files uploaded to github
and for more about DigitalOcean Kubernetes Challenge