Skip to content

Instantly share code, notes, and snippets.

@guenter
Created March 9, 2018 17:25
Show Gist options
  • Save guenter/7e4b848bbb900105e87d19d9ffa780cd to your computer and use it in GitHub Desktop.
Save guenter/7e4b848bbb900105e87d19d9ffa780cd to your computer and use it in GitHub Desktop.
Demo Kubernetes on DC/OS

Setup

These instructions are for DC/OS 1.11.0 and Kubernetes package 1.0.0-1.9.3.

Service Accounts

Install the DC/OS Enterprise CLI, then create a keypair and a service account for Kubernetes. Securely store the private key in the DC/OS secrets store.

dcos package install dcos-enterprise-cli --yes
dcos security org service-accounts keypair private-key.pem public-key.pem
dcos security org service-accounts create -p public-key.pem -d 'kubernetes service account' kubernetes
dcos security secrets create-sa-secret private-key.pem kubernetes kubernetes/sa
dcos security org groups add_user superusers kubernetes

Cassandra

The app stores data in Cassandra. Install the package and create the schema.

dcos package install cassandra --yes
dcos node ssh --master-proxy --leader
docker run -it cassandra:3.0.13 cqlsh node-0-server.cassandra.autoip.dcos.thisdcos.directory

CREATE KEYSPACE browsers WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

CREATE TABLE browsers.browser_counts (
  counter counter,
  os varchar,
  PRIMARY KEY (os)
);

Demo

Public URL: http://k8s.dcos.io

Install Kubernetes

dcos package install --yes kubernetes --options=k8s-package-options.json

Show progress in the UI or CLI:

dcos kubernetes plan status deploy

Connect

dcos kubernetes kubeconfig
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -N -L 9000:apiserver-insecure.kubernetes.l4lb.thisdcos.directory:9000 core@

Kubernetes dashboard

http://localhost:8001/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy/

Using the CLI to manage Kubernetes

Use kubectl to deploy pods on Kubernetes.

kubectl create -f os-detector-white.yaml

kubectl get pods

kubectl describe pod NAME

kubectl set image deployment/osdetect osdetector=smugcloud/osdetector:purple

kubectl get pods

Scale up K8s cluster

Edit the number of nodes in the options file and run:

dcos kubernetes update --options=k8s-package-options.json

View progress in the UI or CLI:

dcos kubernetes plan status update

Kill and heal etcd

dcos task exec -it
pkill etcd
dcos task log

Version update

Can't do this with GA right now because there is only one GA version published.

dcos package install beta-kubernetes --package-version=0.6.0-1.9.1-beta --yes
dcos beta-kubernetes update --name=/kubernetes --package-version=0.6.1-1.9.3-beta --yes

Cleanup

dcos package uninstall kubernetes --yes
dcos security org service-accounts delete kubernetes
dcos security secrets delete kubernetes/sa
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: osdetect
spec:
replicas: 5
template:
metadata:
name: osdetector
labels:
app: osdetector
spec:
containers:
- name: osdetector
image: smugcloud/osdetector:purple
imagePullPolicy: Always
args: ["--cassandra-host", "node-0-server.cassandra.autoip.dcos.thisdcos.directory"]
ports:
- containerPort: 8080
---
kind: Service
apiVersion: v1
metadata:
name: osdetect
spec:
selector:
app: osdetector
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 31000
type: NodePort
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: osdetect
spec:
replicas: 5
template:
metadata:
name: osdetector
labels:
app: osdetector
spec:
containers:
- name: osdetector
image: smugcloud/osdetector:white
imagePullPolicy: Always
args: ["--cassandra-host", "node-0-server.cassandra.autoip.dcos.thisdcos.directory:9042"]
ports:
- containerPort: 8080
---
kind: Service
apiVersion: v1
metadata:
name: osdetect
spec:
selector:
app: osdetector
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 31000
type: NodePort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment