Skip to content

Instantly share code, notes, and snippets.

View jugatsu's full-sized avatar

Anton Kvashenkin jugatsu

View GitHub Profile
@jugatsu
jugatsu / kubernates-the-hard-way-ansible-03-compute-resosurces.md
Created November 23, 2017 14:19
kubernates-the-hard-way-ansible-03-compute-resosurces.md
---

- name: Ensure compute resources are present
  hosts: localhost
  connection: local
  gather_facts: no

  vars:
    service_account_email: [email protected]
@jugatsu
jugatsu / reddit-on-kubernets.md
Last active November 20, 2017 05:08
reddit-on-kubernets.md
$ minikube start
$ kubectl run ui --image=jugatsu/ui --port=9292
$ kubectl run mongo --image=mongo --port=27017
$ kubectl run post --image=jugatsu/post --port=5000 --env="POST_DATABASE_HOST=mongo"
$ kubectl run comment --image=jugatsu/comment --port=9292 --env="COMMENT_DATABASE_HOST=mongo"

$ kubectl expose deploy ui --type=LoadBalancer
$ kubectl expose deploy/mongo
$ kubectl expose deploy/post
# create 3 nodes
$ for i in 1 2 3; do docker-machine create -d virtualbox node-$i; done

# init swarm
node-1 $ docker swarm init --advertise-addr 192.168.99.103

# join swarm
node-2 $ docker swarm join --token YOUR_TOKEN 192.168.99.103:2377
# Copyright 2013 Google Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
Traceback (most recent call last):
File "./gce.py", line 508, in <module>
GceInventory()
File "./gce.py", line 170, in __init__
self.driver = self.get_gce_driver()
File "./gce.py", line 318, in get_gce_driver
gce = get_driver(Provider.GCE)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/libcloud/compute/drivers/gce.py", line 1801, in __init__
self.zone_list = self.ex_list_zones()
File "/Library/Python/2.7/site-packages/libcloud/compute/drivers/gce.py", line 2755, in ex_list_zones
➜ stage git:(terraform-service-account) ✗ /Users/ak/Downloads/google-cloud-sdk/bin/gcloud auth activate-service-account --key-file=ansible-gce.json
Activated service account credentials for: [[email protected]]
➜ stage git:(terraform-service-account) ✗
➜ stage git:(terraform-service-account) ✗
➜ stage git:(terraform-service-account) ✗ /Users/ak/Downloads/google-cloud-sdk/bin/gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
reddit-db europe-west1-b g1-small 10.132.0.2 35.189.235.188 RUNNING
➜ stage git:(terraform-service-account) ✗
➜ stage git:(terraform-service-account) ✗
➜ stage git:(terraform-service-account) ✗

Самостоятельное задание

Исследовать способ подключения к internalhost в одну команду из вашего рабочего устройства, проверить работоспособность найденного решения и отписать вариант решения преподавателю.

Бонусная часть: Предложить вариант решения для подключения из консоли при помощи команды вида ssh internalhost из локальной консоли рабочего устройства, чтобы подключение выполнялось по алиасу internalhost

Вариант №1: используем SSH Port Forwarding

# строим туннель до хоста 10.156.0.3, расположенного в приватной сети
ak@ak-pc:~$ tree code/chef/cookbooks/gf_chef_client/
code/chef/cookbooks/gf_chef_client/
├── attributes
│   └── default.rb
├── Berksfile
├── Berksfile.lock
├── chefignore
├── metadata.rb
├── recipes
@rem
@rem Author:: Seth Chisamore (<[email protected]>)
@rem Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
@rem License:: Apache License, Version 2.0
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
Converging <tasks-windows-hyper-v-2016>...
Preparing files for transfer
Preparing dna.json
Resolving cookbook dependencies with Berkshelf 5.6.0...
Removing non-cookbook files before transfer
Preparing validation.pem
Preparing client.rb
-----> Chef Omnibus installation detected (install only if missing)
Transferring files to <tasks-windows-hyper-v-2016>
Starting Chef Client, version 12.19.36