OpenStack: Magnum

Documentation
https://docs.openstack.org/magnum/latest/user/

Pre-requirements

# install OSC magnum client to fix "a bytes-like object is required, not 'str'"
echo "deb http://archive.ubuntu.com/ubuntu hirsute main restricted" > /etc/apt/sources.list.d/hirsute.list
apt update
apt install -y python3-magnumclient
 
# install kubectl
snap install kubectl --classic

CLI

openstack stack list
openstack stack show d8a1c3af-7993-4493-91be-19cfce38a870
openstack coe cluster update k8s-cluster replace node_count=2

Configure deployment kolla-ansible

# cat /etc/kolla/config/magnum.conf 
[cinder]
default_docker_volume_type = VT1
 
[trust]
cluster_user_trust = True
 
/etc/kolla/config/heat.conf 
[DEFAULT]
#region_name = ch-zh1
region_name_for_services = RegionOne
 
# /etc/kolla/globals.yml 
# magnum_tag: "7.0.0.1"
enable_magnum: "yes"

Redeploy / Reconfigure container

kolla-ansible -i /etc/kolla/inventory-hosts deploy -t magnum

Get Fedora AtomicHost images
https://dl.fedoraproject.org/pub/alt/atomic/stable/?C=M;O=D

# wget https://dl.fedoraproject.org/pub/alt/atomic/stable/Fedora-29-updates-20191126.0/AtomicHost/x86_64/images/Fedora-AtomicHost-29-20191126.0.x86_64.raw.xz
wget https://download.fedoraproject.org/pub/alt/atomic/stable/Fedora-29-updates-20190429.0/AtomicHost/x86_64/images/Fedora-AtomicHost-29-20190429.0.x86_64.raw.xz
xz -d Fedora-AtomicHost-29-20190429.0.x86_64.raw.xz
 
openstack image create "Fedora AtomicHost 29 (20190429.0)" \
  --file Fedora-AtomicHost-29-20190429.0.x86_64.raw.xz \
  --disk-format raw \
  --container-format=bare \
  --min-disk 10 \
  --min-ram 4096 \
  --public \
  --protected \
  --property hw_scsi_model=virtio-scsi \
  --property hw_disk_bus=scsi \
  --property hw_qemu_guest_agent=yes \
  --property os_distro=fedora-atomic \
  --property os_admin_user=fedora \
  --property os_version=20190429.0

Deploy kubernetes cluster

openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
 
openstack flavor create m1.kubernetes \
  --disk 40 \
  --vcpu 2 \
  --ram 4096 \
  --public \
  --description "kubernetes flavor"
 
openstack coe cluster template create kubernetes-cluster-template \
  --image "Fedora AtomicHost 29" \
  --external-network public \
  --dns-nameserver 8.8.8.8 \
  --master-flavor m1.kubernetes \
  --flavor m1.kubernetes \
  --coe kubernetes \
  --volume-driver cinder \
  --network-driver flannel \
  --docker-volume-size 40
 
  # --docker-storage-driver overlay
  # --tls-disabled
  # --floating-ip-disabled
 
# defile application credentials
export OS_CLOUD=dev-foo-app-unrestricted
 
# list avaiable cluster
openstack coe cluster template list
 
export OS_COE_TEMPLATE=k8s-1.15.3-no-floating-ips
export OS_USER_KEY=foo-key
 
# deploy single master cluster
openstack coe cluster create ${CLUSTER} \
  --cluster-template ${OS_COE_TEMPLATE} \
  --master-count 1 \
  --node-count 2 \
  --keypair ${OS_USER_KEY}

Get cluster configurations

cd ~/2.7.15
for CLUSTER in $(openstack coe cluster list -c name -f value); do
  mkdir -p ~/kubernetes/${CLUSTER}
  openstack coe cluster config ${CLUSTER} --dir ~/kubernetes/${CLUSTER} --force
 
  # export latest cluster config as default
  export KUBECONFIG=~/kubernetes/${CLUSTER}/config
done
cat ${KUBECONFIG}
#--use-keystone
 
# Fix taints
 
# kubernetes
kubectl get nodes -o wide
kubectl get pods --all-namespaces -o wide
 
# Configure persistent default cluster
echo "export KUBECONFIG=~/kubernetes/kubernetes-cluster1/config" >> ~/.bashrc
 
# optional: Route to dev public net trougth rally VM
sshuttle --remote rally.dev.i.example.com 10.0.11.0/24

Debug

# operating system
systemctl list-units --failed
journalctl -f
journalctl -p err -b

Fix taints (deprected)

kubectl describe nodes | grep Taints
kubectl taint nodes --all node.cloudprovider.kubernetes.io/uninitialized-
# kubectl taint nodes --all   dedicated=master:NoSchedule-

Repository
https://opendev.org/openstack/magnum/
https://opendev.org/openstack/magnum/commits/branch/stable/rocky - commits to rocky

# kolla-build.conf
[magnum-base]
type = git
location = https://git.openstack.org/openstack/magnum
reference = stable/stein
 
 
# build
cd ./kolla && python tools/build.py --config-file /root/kolla-build.conf --tag 7.0.1.1.foo magnum

Deploy Kubernetes UI
http://www.panticz.de/kubernetes-dashboard-ui

OpenStack Magnum / Kubernetes
Compatibility: https://wiki.openstack.org/wiki/Magnum#Compatibility_Matrix
openstackmagnum Docker registry: https://hub.docker.com/u/openstackmagnum
kubernetes version: https://docs.openstack.org/magnum/latest/user/#kube-tag
latest tag: https://hub.docker.com/r/openstackmagnum/kubernetes-kubelet/tags

cloud-provider-openstack
Repository: https://github.com/kubernetes/cloud-provider-openstack
https://github.com/kubernetes/cloud-provider-openstack/releases
k8scloudprovider Docker registry: https://hub.docker.com/u/k8scloudprovider
cloud provider version: https://docs.openstack.org/magnum/latest/user/#cloud-provider-tag
latest tag: https://hub.docker.com/r/k8scloudprovider/openstack-cloud-controller-manager/tags/?page=1&ordering=name

Get floating IP

openstack loadbalancer list
openstack loadbalancer show 301a787a-a0d4-4989-9d5a-e389330ff44e -c vip_address -f value
openstack floating ip list --fixed-ip-address 10.0.0.5  -c "Floating IP Address" -f value

Scale up

openstack loadbalancer pool list
openstack loadbalancer member list 922266b9-63b2-4e91-ae87-9a6f16525839
kubectl get nodes -o wide
openstack coe cluster update kubernetes-cluster1 replace node_count=4

Get cluster configuration

# specify OpenStack cloud
export OS_CLOUD=dev-foo
 
# Get all cluster configurations
for CLUSTER in $(openstack coe cluster list -c name -f value); do
  mkdir -p ~/kubernetes/${CLUSTER}
  openstack coe cluster config ${CLUSTER} --dir ~/kubernetes/${CLUSTER} --force
done
 
# Export cluster configuration as default
export KUBECONFIG=~/kubernetes/clusterX/config
 
# fix Failed to create trustee or trust for Cluster:
#use unrestriced application credentials 
 
# Define default Kubernetes cluster and load configuration on login
ln -fs ~/kubernetes/clusterX ~/kubernetes/cluster
echo "export KUBECONFIG=~/kubernetes/cluster/config" >> ~/.bashrc

Deploy test container

# deploy nginx
kubectl create deployment nginx --image=nginx
kubectl scale deployment --replicas 2 nginx
 
kubectl get deployments -o wide
kubectl get pods -o wide
 
kubectl expose deployment nginx --type=LoadBalancer --name=nginx --port=80
kubectl get services -o wide
 
# deploy apache
kubectl create deployment httpd2 --image=httpd

Debug

openstack coe cluster list -c uuid -c status -f value | awk '/FAILED/ {print $1}'

Deploy cluster with Ansible

---
- name: Create Kubernetes cluster
  os_coe_cluster:
    cloud: "{{ os_cloud }}"
    name: "{{ os_user }}-k8s-1.15.3-floating-ips"
    cluster_template_id: k8s-1.15.3-floating-ips
    keypair: "{{ os_user }}-key"
    master_count: 1
    node_count: 2

Show COE service state

openstack coe service list

Next: Kubernetes
http://www.panticz.de/kubernetes

Links
#openstack-containers channel
https://fedorapeople.org/groups/magnum/ - old Fedora Atomic host images (deprected?)