Merge branch 'master' into k8s2d

This commit is contained in:
Jerome Petazzoni
2018-09-29 10:06:37 -05:00
10 changed files with 195 additions and 28 deletions

View File

@@ -53,11 +53,18 @@ _cmd_deploy() {
echo deploying > tags/$TAG/status
sep "Deploying tag $TAG"
# Wait for cloudinit to be done
pssh "
while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
sleep 1
done"
# Copy settings and install Python YAML parser
pssh -I tee /tmp/settings.yaml <tags/$TAG/settings.yaml
pssh "
sudo apt-get update &&
sudo apt-get install -y python-setuptools &&
sudo easy_install pyyaml"
sudo apt-get install -y python-yaml"
# Copy postprep.py to the remote machines, and execute it, feeding it the list of IP addresses
pssh -I tee /tmp/postprep.py <lib/postprep.py
@@ -178,6 +185,14 @@ EOF"
sep "Done"
}
_cmd kubereset "Wipe out Kubernetes configuration on all nodes"
_cmd_kubereset() {
TAG=$1
need_tag
pssh "sudo kubeadm reset --force"
}
_cmd kubetest "Check that all nodes are reporting as Ready"
_cmd_kubetest() {
TAG=$1
@@ -261,6 +276,15 @@ _cmd_opensg() {
infra_opensg
}
_cmd pssh "Run an arbitrary command on all nodes"
_cmd_pssh() {
TAG=$1
need_tag
shift
pssh "$@"
}
_cmd pull_images "Pre-pull a bunch of Docker images"
_cmd_pull_images() {
TAG=$1
@@ -376,6 +400,22 @@ _cmd_test() {
test_tag
}
# Sometimes, weave fails to come up on some nodes.
# Symptom: the pods on a node are unreachable (they don't even ping).
# Remedy: wipe out Weave state and delete weave pod on that node.
# Specifically, identify the weave pod that is defective, then:
# kubectl -n kube-system exec weave-net-XXXXX -c weave rm /weavedb/weave-netdata.db
# kubectl -n kube-system delete pod weave-net-XXXXX
_cmd weavetest "Check that weave seems properly setup"
_cmd_weavetest() {
TAG=$1
need_tag
pssh "
kubectl -n kube-system get pods -o name | grep weave | cut -d/ -f2 |
xargs -I POD kubectl -n kube-system exec POD -c weave -- \
sh -c \"./weave --local status | grep Connections | grep -q ' 1 failed' || ! echo POD \""
}
greet() {
IAMUSER=$(aws iam get-user --query 'User.UserName')
info "Hello! You seem to be UNIX user $USER, and IAM user $IAMUSER."
@@ -501,12 +541,3 @@ make_tag() {
fi
date +%Y-%m-%d-%H-%M-$USER
}
describe_tag() {
FIXME
# Display instance details and reachability/status information
TAG=$1
need_tag $TAG
aws_display_instances_by_tag $TAG
aws_display_instance_statuses_by_tag $TAG
}

View File

@@ -94,14 +94,11 @@ wait_until_tag_is_running() {
done_count=0
while [[ $done_count -lt $COUNT ]]; do
let "i += 1"
info "$(printf "%d instances online" $done_count)"
info "$(printf "%d/%d instances online" $done_count $COUNT)"
done_count=$(aws ec2 describe-instances \
--filters "Name=instance-state-name,Values=running" \
"Name=tag:Name,Values=$TAG" \
--query "Reservations[*].Instances[*].State.Name" \
| tr "\t" "\n" \
| wc -l)
--filters "Name=tag:Name,Values=$TAG" \
"Name=instance-state-name,Values=running" \
--query "length(Reservations[].Instances[])")
if [[ $i -gt $max_retry ]]; then
die "Timed out while waiting for instance creation (after $max_retry retries)"
fi
@@ -165,7 +162,6 @@ aws_get_instance_ids_by_filter() {
aws_get_instance_ids_by_client_token() {
TOKEN=$1
need_tag $TOKEN
aws_get_instance_ids_by_filter Name=client-token,Values=$TOKEN
}

View File

@@ -83,7 +83,7 @@ system("sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /e
system("sudo service ssh restart")
system("sudo apt-get -q update")
system("sudo apt-get -qy install git jq python-pip")
system("sudo apt-get -qy install git jq")
#######################
### DOCKER INSTALLS ###
@@ -98,7 +98,6 @@ system("sudo apt-get -q update")
system("sudo apt-get -qy install docker-ce")
### Install docker-compose
#system("sudo pip install -U docker-compose=={}".format(COMPOSE_VERSION))
system("sudo curl -sSL -o /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/{}/docker-compose-{}-{}".format(COMPOSE_VERSION, platform.system(), platform.machine()))
system("sudo chmod +x /usr/local/bin/docker-compose")
system("docker-compose version")

View File

@@ -20,8 +20,8 @@ paper_margin: 0.2in
engine_version: stable
# These correspond to the version numbers visible on their respective GitHub release pages
compose_version: 1.21.1
machine_version: 0.14.0
compose_version: 1.22.0
machine_version: 0.15.0
# Password used to connect with the "docker user"
docker_user_password: training
docker_user_password: training

View File

@@ -32,7 +32,8 @@
--
OK, what just happened?
(Starting with Kubernetes 1.12, we get a message telling us that
`kubectl run` is deprecated. Let's ignore it for now.)
---
@@ -228,6 +229,44 @@ We could! But the *deployment* would notice it right away, and scale back to the
---
## What about that deprecation warning?
- As we can see from the previous slide, `kubectl run` can do many things
- The exact type of resource created is not obvious
- To make things more explicit, it is better to use `kubectl create`:
- `kubectl create deployment` to create a deployment
- `kubectl create job` to create a job
- Eventually, `kubectl run` will be used only to start one-shot pods
(see https://github.com/kubernetes/kubernetes/pull/68132)
---
## Various ways of creating resources
- `kubectl run`
- easy way to get started
- versatile
- `kubectl create <resource>`
- explicit, but lacks some features
- can't create a CronJob
- can't pass command-line arguments to deployments
- `kubectl create -f foo.yaml` or `kubectl apply -f foo.yaml`
- all features are available
- requires writing YAML
---
## Viewing logs of multiple pods
- When we specify a deployment name, only one single pod's logs are shown

View File

@@ -192,3 +192,38 @@ Note: it might take a minute or two for the app to be up and running.
```
]
---
## Switching namespaces more easily
- Defining a new context for each namespace can be cumbersome
- We can also alter the current context with this one-liner:
```bash
kubectl config set-context --current --namespace=foo
```
- We can also use a little helper tool called `kubens`:
```bash
# Switch to namespace foo
kubens foo
# Switch back to the previous namespace
kubens -
```
---
## `kubens` and `kubectx`
- With `kubens`, we can switch quickly between namespaces
- With `kubectx`, we can switch quickly between contexts
- Both tools are simple shell scripts available from https://github.com/ahmetb/kubectx
- On our clusters, they are installed as `kns` and `kctx`
(for brevity and to avoid completion clashes between `kubectx` and `kubectl`)

View File

@@ -55,6 +55,7 @@ chapters:
- swarm/apiscope.md
- - swarm/logging.md
- swarm/metrics.md
- swarm/gui.md
- swarm/stateful.md
- swarm/extratips.md
- shared/thankyou.md

51
slides/swarm/gui.md Normal file
View File

@@ -0,0 +1,51 @@
# GUI's: Web Admin of Swarms and Registry
What about web interfaces to control and manage Swarm?
- [Docker Enterprise](https://www.docker.com/products/docker-enterprise) is Docker Inc's paid offering, which has GUI's.
- [Portainer](https://portainer.io) is a popular open source web GUI for Swarm with node agents.
- [Portus](http://port.us.org) is a SUSE-backed open source web GUI for registry.
- Find lots of other Swarm tools in the [Awesome Docker list](http://awesome-docker.netlify.com).
---
## Lets deploy Portainer
- Yet another stack file
.exercise[
- Make sure we are in the stacks directory:
```bash
cd ~/container.training/stacks
```
- Deploy the Portainer stack:
```bash
docker stack deploy -c portainer.yml portainer
```
]
---
## View and setup Portainer
- go to `<node ip>:9090`
- You should see the setup UI. Create a 8-digit password.
- Next, tell Portainer how to connect to docker.
- We'll use the agent method (one per node).
- For connection, choose `Agent`
- Name: `swarm1`
- Agent URL: `tasks.agent:9001`
- Let's browse around the interface

View File

@@ -1,8 +1,8 @@
## Brand new versions!
- Engine 18.03
- Compose 1.21
- Machine 0.14
- Engine 18.06
- Compose 1.22
- Machine 0.15
.exercise[

15
stacks/portainer.yml Normal file
View File

@@ -0,0 +1,15 @@
version: "3.4"
services:
web:
image: portainer/portainer
ports:
- "9000:9000"
agent:
image: portainer/agent
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
mode: global
environment:
AGENT_CLUSTER_ADDR: tasks.agent