Blog | CloudStakes Technology
1709709453Deploy Spinnaker using Google Kubernetes Engine.webp

How to Deploy Spinnaker using Google Kubernetes Engine?

user-img

Nikita Gill

18th February 2022

Spinnaker is an open-source, multi-cloud-based continuous delivery platform helping developers to release software amendments with speed and confidence. This platform is made open source by Netflix and managed by Google; thus, it supports most cloud platforms and their supporting tools, including Google cloud platform, AWS, Microsoft Azure, Openstack, App Engine, Kubernetes, and many others. The main reason behind using Spinnaker is that it helps developers in cloud-based application deployment and management processes. Now, let’s start the deployment process of Spinnaker.

Step 1: Creating A Kubernetes Cluster Using Google Kubernetes Engine

Prerequisites for Kubernetes Cluster:

  • Availability of at least 2 vCPU
  • RAM: 13 GB (min)
  • One schedulable node
  • Functional networking to communicate with the world outside

Steps to spin up Kubernetes cluster:

  • Set up a Google Cloud account and enable the billing status.
  • Configure the Google Cloud SDK on the same machine, you’ll be using to control the Kubernetes cluster.
  • Navigate to the Console and follow the path: Computer > Kubernetes Engine > Kubernetes Cluster
  • And click on the Create Cluster and specify its name as per your requirement.
  • Click on the Customize button available below Machine Type.
  • In the Machine Type section, specify the Cores with 2 vCPU and Memory with 10GB RAM

create a Kubernetes Cluster

  • Specify the Cluster Size to 1, keep the rest of the fields with their default values, and finally, click on the Create button present at the bottom.

Set up a Kubernetes cluster

  • After a couple of minutes of processing, you can see your Kubernetes cluster ready on the Kubernetes Clusters page. 

Step 2: Creating Kubernetes Objects for Spinnaker
  • First, configure the kubectl to access the recently created Kubernetes cluster. Here, we’ve mentioned steps to configure kubectl for a GKE cluster. Go to the Kubernetes clusters page, click on the Connect and copy the command by clicking on the Copy icon and paste that command on the command line window.
gcloud container clusters get-credentials cluster-2 --zone us-central1-a --project nick-chase
  • Create an account for the use of Halyard, Spinnaker’s deployment tool. But at first, create a text file named spinnacct.yaml and add the following lines into it:
apiVersion: v1 
kind: ServiceAccount 
metadata: 
  name: spinnaker-service-account 
  namespace: default 
--- 
apiVersion: rbac.authorization.k8s.io/v1 
kind: ClusterRoleBinding 
metadata: 
  name: spinnaker-role-binding 
roleRef: 
  apiGroup: rbac.authorization.k8s.io 
  kind: ClusterRole 
  name: cluster-admin 
subjects: 
- namespace: default 
  kind: ServiceAccount 
  name: spinnaker-service-account

It creates another account called spinnaker-service-account and assigns the cluster-admin role for security purposes. Now, save the data and close the file.

  • Run the script with kubectl to create an account.
kubectl create -f spinacct.yaml 
  • Create the Spinnaker namespace using the following command:
kubectl create namespace spinnaker 
  • Now, create services. For that, you’ll have to create a text file named spinsvcs.yaml incorporated with the following lines, which will create two load balancers on port numbers 8084 and 9000, respectively. You can also use SSH tunnelling in case Kubernetes clusters find unable to support load balancers.
apiVersion: v1 
kind: Service 
metadata: 
  namespace: spinnaker 
  labels: 
    app: spin 
    stack: gate 
  name: spin-gate-np 
spec: 
  type: LoadBalancer 
  ports: 
  - name: http 
    port: 8084 
    protocol: TCP 
  selector: 
    load-balancer-spin-gate: "true" 
--- 
apiVersion: v1 
kind: Service 
metadata: 
  namespace: spinnaker 
  labels: 
    app: spin 
    stack: deck 
  name: spin-deck-np 
spec: 
  type: LoadBalancer 
  ports: 
  - name: http 
    port: 9000 
    protocol: TCP 
  selector: 
    load-balancer-spin-deck: "true"
  • Run the script to create the services. The following shows the output of created services:
kubectl create -f spinsvcs.yaml 
Step 3: Preparing to Configure the Spinnaker Deployment
  • Use the following command to create a deployment to host Halyard:
kubectl create deployment hal --image gcr.io/spinnaker-marketplace/halyard:1.5.0
  • Kubernetes will take a couple of minutes to download the image. In the meantime, you can go ahead to edit the hal command for accessing the spinnaker account.

kubectl edit deploy hal

  • Regardless of the OS type, it is advisable to specify the serviceAccountName to the cluster spec as follows:
... 
    spec: 
      serviceAccountName: spinnaker-service-account 
      containers: 
      - image: gcr.io/spinnaker-marketplace/halyard:stable 
        imagePullPolicy: IfNotPresent 
        name: halyard 
        resources: {} 
...
  • Save and close the cluster service file. After that, Kubernetes will initiate the editing of the Spinnaker deployment and create a new pod with new credentials.
deployment "hal" edited 
  • Execute the pod to know its name, status, and age: 
kubectl get pods 

It shows the creation of a container. Hence, wait until the container begins to run.

  • Connect kubectl with bash inside the container:
kubectl exec -it hal-65fdf47fb7-tq4r8 bash  

This command will take you to the container command-line interface. Now change the Spinnaker user home directory:

spinnaker@hal-65fdf47fb7-tq4r8:/workdir# cd 
spinnaker@hal-65fdf47fb7-tq4r8:~# 
  • Interact with Kubernetes with installed kubectl:
kubectl config set-cluster default --server=https://kubernetes.default --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt 
kubectl config set-context default --cluster=default 
token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) 
kubectl config set-credentials user --token=$token 
kubectl config set-context default --user=user 
kubectl config use-context default 
  • Now, another tool you’ll need in the Spinnaker deployment process is Helm. Run the following script to install helm without sudo or root access:
sed -i 's/\/usr\/local\/bin/\/home\/spinnaker/g' get_helm.sh 
sed -i 's/sudo //g' get_helm.sh 
export PATH=/home/spinnaker:$PATH

Now, run the script. The following screen shows the Helm installation process:

spinnaker@hal-65fdf47fb7-tq4r8:~# chmod 700 get_helm.sh 
spinnaker@hal-65fdf47fb7-tq4r8:~# ./get_helm.sh 
  • Use the tiller account that we created earlier to run the Help configuration against the Kubernetes cluster and upgrade the tiller.
helm init --service-account tiller --upgrade 

Now, it’s time to proceed with the actual spinnaker configuration.

Step 4: Configuring the Spinnaker Deployment
  • Go to the halyard container, open the command-line interface, and start configuring the Docker registry using a public repo named library/nginx. Then, run the script to see the output.
ADDRESS=index.docker.io 
REPOSITORIES=library/nginx  
hal config provider docker-registry enable 
hal config provider docker-registry account add my-docker-registry \ 
   --address $ADDRESS \ 
   --repositories $REPOSITORIES 
  • Add Mirantis Helm chart repo to configure Minio – the storage provider.
helm repo add mirantisworkloads https://mirantisworkloads.storage.googleapis.com
  • Install Minio
helm install mirantisworkloads/minio 
  • Configure Minio access key and password and Halyard with specific storage choice:
MINIO_ACCESS_KEY=miniokey 
MINIO_SECRET_KEY=miniosecret 
echo $MINIO_SECRET_KEY | hal config storage s3 edit --endpoint $ENDPOINT \ 
   --access-key-id $MINIO_ACCESS_KEY \ 
   --secret-access-key 
hal config storage edit --type s3 
  • Enable Kubernetes
hal config provider kubernetes enable 
hal config provider kubernetes account add my-k8s-account --docker-registries my-docker-registry 
hal config deploy edit --type distributed --account-name my-k8s-account 
  • Define the version of the Spinnaker Deployment
hal config version edit --version 1.8.1 
  • Find the IPs of Spinnaker services
kubectl get svc -n spinnaker 
  • Configure UI for the EXTERNAL-IP for port 9000 and API for the EXTERNAL-IP port 8084
hal config security ui edit --override-base-url http://35.184.29.246:9000  
hal config security api edit --override-base-url http://35.193.195.231:8084 
Step 5: Deploy Spinnaker
  • Use the following command to deploy Spinnaker
hal deploy apply 
  • Open the second console to check pods in the Spinnaker:
kubectl get pods -n spinnaker 

After you press enter, it will start listing pods that are running and ready, and if there aren’t, consider that you’ve to perform some operation to see such a list.

Conclusion:

Now, you’re all set to use your spinnaker to create new applications by following the path: Actions -> Create Application. If that works, consider your spinnaker is successfully deployed. Looking for the best cloud computing services provider? In that case, you’ve come to the right place. We, at CloudStakes Technology Pvt. Ltd., have cloud computing solutions to all your cloud-related issues. Book your first free cloud consultation with our cloud experts TODAY!!