Skip to content

Commit

Permalink
update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dongitran committed Nov 27, 2023
1 parent 83b70b5 commit 3f3b5a1
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
33 changes: 23 additions & 10 deletions .github/workflows/deploy-kubernetes-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,38 @@ jobs:
uses: actions/checkout@v2

- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
export_default_credentials: true
run: |
curl -o google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-372.0.0-linux-x86_64.tar.gz
tar -xf google-cloud-sdk.tar.gz
./google-cloud-sdk/install.sh --quiet
echo "${{ secrets.GCLOUD_AUTH }}" > /tmp/gcloud.json
./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file=/tmp/gcloud.json
./google-cloud-sdk/bin/gcloud config set project ${{ secrets.GCP_PROJECT_ID }}
- name: Configure Docker CLI
run: |
gcloud auth configure-docker
./google-cloud-sdk/bin/gcloud auth configure-docker
- name: Build and push Docker image
run: |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/your-image-name .
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/your-image-name
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/kubernetes-engine-ci-cd-template .
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/kubernetes-engine-ci-cd-template
- name: Install kubectl plugin
run: |
./google-cloud-sdk/bin/gcloud components install kubectl
- name: Set kubectl context
run: |
gcloud container clusters get-credentials ${{ secrets.GCP_CLUSTER_NAME }} --zone ${{ secrets.GCP_CLUSTER_ZONE }} --project ${{ secrets.GCP_PROJECT_ID }}
./google-cloud-sdk/bin/gcloud container clusters get-credentials ${{ secrets.GCP_CLUSTER_NAME }} --zone ${{ secrets.GCP_CLUSTER_ZONE }} --project ${{ secrets.GCP_PROJECT_ID }}
- name: Configure kubectl
run: |
gcloud auth activate-service-account --key-file=/tmp/gcloud.json
kubectl config set-credentials gke-cluster-user --token=$(gcloud auth print-access-token)
kubectl config set-context gke-cluster --cluster=${{ secrets.GCP_CLUSTER_CONTEXT }} --user=gke-cluster-user
kubectl config use-context gke-cluster
- name: Deploy to Kubernetes
run: |
kubectl apply -f path/to/your/kubernetes/config.yaml
kubectl apply -f deployment.yaml
60 changes: 60 additions & 0 deletions deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-1
namespace: default
labels:
app: nginx-1
spec:
replicas: 3
selector:
matchLabels:
app: nginx-1
template:
metadata:
labels:
app: nginx-1
spec:
containers:
- name: nginx-container
image: gcr.io/cdtest-406103/kubernetes-engine-ci-cd-template:latest
ports:
- containerPort: 8080

---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nginx-1-hpa-zylx
namespace: default
labels:
app: nginx-1
spec:
scaleTargetRef:
kind: Deployment
name: nginx-1
apiVersion: apps/v1
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80

---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: default
spec:
selector:
app: nginx-1
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: LoadBalancer

0 comments on commit 3f3b5a1

Please sign in to comment.