Showing posts with label kubernetes. Show all posts
Showing posts with label kubernetes. Show all posts

1/8/19

How to connect to gcp cluster from local terminal

Firstly you need Kubernetes installed on your machine

brew install kubernetes-cli
Open the cloud console UI, and navigate to "clusters" tab.
You will present with popup that displays command with exact parameters of the specific cluster

Note: if you already logged with different account - run "gcloud auth revoke --all"
and then: "gcloud auth login"

Now you can run the command in the console. It may happen you will be prompted with chrome asking for cloud credentials. After you get logged in, you can verify that you are in the correct cluster by, for example, checking for pods status:

kubectl get pods

10/24/18

Kubernetes - Old replica sets remains after deployment

In this post i will write about annoying Kubernetes problem I managed to solve (at least I think it solved)
after long struggle.

So, here is the problem:

After running update-deployment-image command:

kubectl set image deployment/my-app my-app=gcr.io/my-cloud/my-app:new-image-tag 
The kubernetes showed that although the new image successfully updated, the old replicaset still remains:



Old replicates are all with 0 pods, but not removed.

Solution

The solution I found is to change the "selector" node in deployment configuration -
From:

  selector:
    matchLabels:
      app: my-app
      version: $SHORT_SHA
To

  selector:
    matchLabels:
      app: my-app
(Remove the "version" label)
And to add revisionHistoryLimit entry

spec:
  replicas: 2
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: my-app

10/16/18

Make travis to push tags

What is travis you already know from the previous post. But what the kubernetes is?
According to the docs: "Kubernetes is a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available"
Get the long things shorter: kubernetes is the way to upload applications to google cloud, and also it can do lots of other things.

My Goal

So, my goal was: to get things published to cloud after all the testing stuff was done. (or after the travis finished)
Google cloud builder - another google cloud tool can be activated in response to push to some branch or in response to publishing some tag

In other words - my goal is to make travis to push tag after successful testing of every commit.

After Success Hook

Fortunately I found that travis has a after_success hook which I can utilise for my scenario:


language: node_js
node_js:
  - "9"
sudo: required
branches:
  except:
    - /^v.*\_.*/ 
dist: trusty
addons:
  chrome: stable
cache:
  directories:
  - $HOME/.npm
env:
  matrix:
    - MONGODB=3.6.6
before_install:
  - export GITHUBKEY=put-here-your-github-auth-token-key
install:
  ...
  ...
script:
  # run build script specified in package.json
  - npm run tslint
  - npm run test
  - npm run build
after_success:
  # CREATE GIT TAG
  - bash ./scripts/push_tag.sh

And here is the bash script code:

#!/bin/sh
git config --global user.email "koko@moko.com"
git config --global user.name "koko"
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
  | grep version \
  | head -1 \
  | awk -F: '{ print $2 }' \
  | sed 's/[",]//g' \
  | tr -d '[[:space:]]')

# should start cloud build only on prod test dev branches 
if [[ "${TRAVIS_BRANCH}" = prod || "${TRAVIS_BRANCH}" = test || "${TRAVIS_BRANCH}" = dev ]]; then
    export GIT_TAG="v${PACKAGE_VERSION}_${TRAVIS_BUILD_NUMBER}"
    echo "tag is ${GIT_TAG}"
    git tag $GIT_TAG -a -m "Generated tag from TravisCI build $TRAVIS_BUILD_NUMBER [ci skip]" $TRAVIS_BRANCH
    git push --tags https://$GITHUBKEY@github.com/oyrname/yourrepo
fi

Notice, that travis will react to the tag pushed by himself unless except entry configured properly:

branches:
  except:
    - /^v.*\_.*/

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...